題目連結
現在給你一個自然數 n,它的位數小于等于一百萬,現在你要做的就是求出這個數整除九之後的餘數。
輸入格式
第一行有一個整數 m(1≤m≤8),表示有 m組測試資料。
随後 m行每行有一個自然數 n。
輸出格式
輸出 n 整除九之後的餘數,每次輸出占一行。
輸出時每行末尾的多餘空格,不影響答案正确性
樣例輸入
3
4
5
465456541
樣例輸出
4
5
4
題意思路:大數取餘好像是用字元串解決的
代碼:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define maxn 1000005
using namespace std;
char str[maxn];
int m;
int main()
{
cin>>m;
while(m--)
{
scanf("%s",&str);
int len=strlen(str);
int t=0;
for(int i=0;i<len;i++)
{
t+=(str[i]-'0')%9;
}
printf("%d\n",t%9);
}
return 0;
}