对于给定的正整数N,求它的位数及其各位数字之和。
输入格式:
输入在一行中给出一个不超过109的正整数N。
输出格式:
在一行中输出N的位数及其各位数字之和,中间用一个空格隔开。
输入样例:
321
输出样例:
3 6
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include <iostream>
using namespace std;
int main()
{
int n, num = 0, tot = 0;
cin>>n;
while(n)
{
tot += n%10;
num++;
n /= 10;
}
cout<<num<<" "<<tot<<endl;
return 0;
}