奋战杭电ACM(DAY9)1013

来源:互联网 发布:windows切换平板模式 编辑:程序博客网 时间:2024/05/05 09:35

Digital Roots

#include <iostream>#include <string>using namespace std;int main(){    string s;//溢出神烦哈!    int m,n,i;    while(cin >> s)    {            m=0;        if(s[0]=='0') break;        for(i=0; s[i]!='\0'; i++)            m+=s[i]-'0';//转换为int,巧妙!        n= ((m%9==0)?9:(m%9));//这个判定很牛啊!!!只是不会证明……        cout << n << endl;    }    return 0;}


原创粉丝点击