题解 | #数字之和#
数字之和
https://www.nowcoder.com/practice/ae759916631f4711a90c4d4d9657f4b0
#include <stdio.h> #include <string.h> typedef long long ll; int count(char *s,int sum){ int length=strlen(s); for(int i=0; i<length; i++) { sum+=(s[i]-'0'); } return sum; } int main(){ char a[6],b[20]; ll temp,power; while(scanf("%s",&a)!=EOF) { sscanf(a,"%d",&temp);//将字符串转为int型 power=temp*temp; sprintf(b,"%lld",power);//将平方后的数值转为字符串 printf("%d %d\n",count(a,0),count(b,0)); } return 0; }