一、题目
二、解析
拆分数字,参见博客:CCF 201912-1 报数【拆分数字】
三、代码
#include <iostream>
using namespace std;
int n;
int digit;
int cnt = 0;
int main()
{
cin >> n;
while (n >= 10) {
digit = n % 10;
n /= 10;
cnt += digit;
}
cnt += n;
cout << cnt << endl;
return 0;
}
输入:
20151220
输出:
13