-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path10494 - If We Were a Child Again_v1.cpp
51 lines (50 loc) · 1.13 KB
/
10494 - If We Were a Child Again_v1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<stdio.h>
#include<string.h>
int main()
{
char ar[1000],c,div[1000];
long long int a,i,j,mod,len,res,flag;
while(scanf("%s %c %lld",ar,&c,&a)==3)
{
flag=mod=0;
if(c=='%')
{
len=strlen(ar);
for(i=0;i<len;i++)
mod=(mod*10+(ar[i]-'0'))%a;
printf("%lld\n",mod);
}
else if(c=='/')
{
mod=res=0;
len=strlen(ar);
for(j=i=0;i<len;i++)
{
res=(mod*10)+(ar[i]-'0');
if(res>=a)
{
div[j++]=res/a+'0';
mod=res%a;
}
else
{
div[j++]='0';
mod=(mod*10+ar[i]-'0');
}
}
div[j]='\0';
for(i=0;i<j;i++)
{
if(div[i]!='0')
flag=1;
if(flag==0)
continue;
printf("%c",div[i]);
}
if(flag==0)
printf("0");
printf("\n");
}
}
return 0;
}