基础语言-题目74(小学算术)

来源:互联网 发布:杭州g20知乎 编辑:程序博客网 时间:2024/03/29 16:31

还是比较简单的,主要是要考虑到几个情况.比如进位给上一位的问题.这个题目还是比较简单的

#include <stdio.h>#include <string.h>#include <iostream>#include <string>#include <algorithm>using namespace std;const int sta = '0';int main(){char a[11], b[11];while (cin >> a >> b){if (a[0] == '0' && b[0] == '0'){break;}int cunt = 0;for (int i = 2; i >= 0; i--){if (a[i] + b[i] - 2 * sta >= 10){if (i != 0){a[i - 1]++;}cunt++;}}cout << cunt << endl;}return 0;} 


原创粉丝点击