标签:style blog color io os ar for sp 数据
现在给你一个自然数n,它的位数小于等于一百万,现在你要做的就是求出这个数整除九之后的余数。
3 4 5 465456541
4 5 4
#include<stdio.h>
#include<string.h>
char a[1000000];//此数组把数字当做字符串读取
int s[1000000];//把字符数组转换存入整形数组中
int main()
{
int m;
scanf("%d",&m);
while(m--)
{
int len,i,ans=0,dp=0;
scanf("%s",a);//读入字符串
len=strlen(a);//计算长度
for(i=0;i<len;i++)
s[i]=a[i]-'0';//把字符串转化为整形存入数组
for(i=0;i<len;i++)
{
ans=(s[i]+dp*10)%9;//求余数
dp=ans;//计算余数,作为下次求余数的十位数字
}
printf("%d\n",dp);//输出最后取得的余数,即为所求
}
}标签:style blog color io os ar for sp 数据
原文地址:http://blog.csdn.net/u013238646/article/details/40351953