题解 | #Integer Inquiry#

Integer Inquiry

https://www.nowcoder.com/practice/df03906024d742cc919a64c22983f5e1

注意数组大小要给够,不然测试用例会失败

#include <iostream>
using namespace std;

int main(){

	string str;
	int s[103] = {0};
    int i,j;
	while (cin >>str && str.size() != 1){
		
		//累和存到s数组
		for ( i = str.size()-1,j=102; i >=0 ;i--){
			s[j--] += str[i]-'0';
		}

		//进位
		for (i = 102; i >= 0;i--){
			if (s[i] >= 10){
				 s[i-1] += s[i]/10;
				 s[i] %= 10;
			}
		}

	}
    //输出
    i = 0;
    while (s[i] == 0)i++;
    for (i; i < 103;i++){
        cout <<s[i];
    }
    cout <<endl;
}

全部评论

相关推荐

重生我想学测开:嵌入式的问题,我准备入行京东外卖了
点赞 评论 收藏
分享
陆续:不可思议 竟然没那就话 那就我来吧 :你是我在牛客见到的最美的女孩
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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