码迷,mamicode.com
首页 > 编程语言 > 详细

hdu1013(C++)

时间:2015-03-01 15:42:27      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

9的余数定理:一个数各位数字的总和除以9的余数与它本身除以9的余数同等

大数问题:防止大数,用字符串来存入数据,再转化为数字

#include<iostream>
#include<string>
using namespace std;
int main()
{
 int N,i;
 string s;
 while (cin>>s)
 {
  if (s[0] - ‘0‘ == 0)
   break;                      //遇0终止
  N = 0;
  for (i = 0; i < s.size(); i++)
   N += s[i] - ‘0‘;         //各位数字之和
  if (N % 9 == 0)
   cout << "9" << endl;
  else
   cout << N % 9 << endl;
 }
 return 0;
}

hdu1013(C++)

标签:

原文地址:http://www.cnblogs.com/td15980891505/p/4307069.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!