题解 | #数字之和#

数字之和

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;
}

全部评论

相关推荐

每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:45
你不要过来啊啊啊啊啊啊啊
码农索隆:对面:“今天你不面也得面”
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务