这道题给的数据非常重要 只要注意到了不用大数的除法都可以做
因为除数是有限大的 用整形就能保存下来 然后就简单了 模拟四则运算 很容易就能做出来了 取模也是一样的
字符串的比较函数用着老错 自己写了一个
下面看代码
#include<cstdio>
#include<cstring>
#define MAX 1000000
#define LL long long
char str[MAX],result[MAX];
void Mod(char *s)
{
int str_len = strlen(str);
int s_len = strlen(s);
LL c = 0;
for(int i = 0; i < s_len; i++)
c =c*10+(s[i]-'0');
LL sum = 0;
for(int i = 0; i < str_len; i++)
{
sum = sum*10 + (str[i] - '0');
if(sum >= c) sum %= c;
}
printf("%lld\n",sum);
}
int cmp(char *p,char *q)
{
if(strlen(p)<strlen(q))return 1;
if(strlen(p)>strlen(q))return 0;
for(int i = 0; i < strlen(q); i++)
if(p[i] > q[i])return 0;
else if(p[i] < q[i])return 1;
return 0;
}
void Division(char *s)
{
int str_len = strlen(str);
int s_len = strlen(s);
LL c = 0;
for(int i = 0; i < s_len; i++)
c =c*10+(s[i]-'0');
LL sum = 0;
int flag = 0;
for(int i = 0; i < str_len; i++)
{
sum = sum*10 + (str[i] - '0');
if(sum >= c)
{
flag = 1;
printf("%lld",sum/c);
sum %=c;
}
else if(flag) printf("0");
}
printf("\n");
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
char sign,c[15];
while(scanf("%s %c %s",str,&sign,c)!=EOF)
{
if(sign == '%')
{
if(cmp(str,c)){puts(str);continue;}
if(strcmp(str,c)==0){printf("0\n");continue;}
Mod(c);
}
else
{
if(cmp(str,c)){printf("0\n");continue;}
if(strcmp(str,c) == 0){printf("1\n");continue;}
Division(c);
}
}
return 0;
}