Digital Roots(九余数定理)

原题地址
很好的一道九余数题。
首先,没告诉你数据范围---->你必须要用字符串来解决
其次,题中隐含了当数字根为9时要输出9,所以要特判一下
代码附上:

#include <vector>
#include<stdio.h>
#include<string.h>
#include <cstring>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <set>
#include<cstring>
#define ll long long
#define MODD 1000000007
#define pii pair<int,int>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    char n[100000];
    while(cin >>n){
        int len = strlen(n);
        ll k =0,sum=0;
        if(len==1&&n[0]=='0')break;
       for(int i=0;i<len;i++){
            k = n[i]-'0';
            sum+=k%9;
       }
       if(sum==0)cout<<9<<endl;
       else      cout<<sum%9<<endl;
    }

}

全部评论

相关推荐

05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务