The remainder nine - large numbers modulo

Topic Link
now give you a natural number n, which is equal to the number of bits less than one million, and now you have to do is find the remainder after a number is divisible by nine.

Input format
first line of an integer m (1≤m≤8), m represents the set of test data there.

Then m lines each have a natural number n.

Output format
output remainder after n divisible by nine each output per line.

Extra spaces at the end of each row, the answer does not affect the validity of the output

Sample input
. 3
. 4
. 5
465 456 541
sample output
. 4
. 5
. 4

Title meaning road: take the remainder of large numbers it seems to solve a string
of code:

#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;
}

Published 81 original articles · won praise 3 · Views 2761

Guess you like

Origin blog.csdn.net/weixin_44641254/article/details/104230650