小學生算術
時間限制:3000 ms | 內存限制:65535 KB 難度:1 描述 很多小學生在學習加法時,發現“進位”特別容易出錯。你的任務是計算兩個三位數在相加時需要多少次進位。你編制的程序應當可以連續處理多組數據,直到讀到兩個0(這是輸入結束標記)。 輸入 輸入兩個正整數m,n.(m,n,都是三位數) 輸出 輸出m,n,相加時需要進位多少次。 樣例輸入 123 456 555 555 123 594 0 0 樣例輸出 0 3 1
#include <iostream>using namespace std;int jin(int m,int n){ int a=n%10; //百位數 int b=n/10%10; //十位數 int c=n/100; //個位數 int d=m%10; //百位數 int e=m/10%10; //十位數 int f=m/100; //個位數 int count=0; if(a+d>=10) { count++; int g=(a+d)%10; if(b+e+g>=10) { count++; int h=(b+e)%10; if(c+f+h>=10) { count++; } } } else if(a+d<10&&b+e>=10) { count++; int i=(b+e)%10; if(i+c+f>=10) { count++; } } else { if(c+f>=10) { count++; } } return count;}int main(){ int m,n; while(cin>>m>>n) { if(m!=0&&n!=0) { cout<<jin(m,n); } else { break; } cout<<endl; } return 0;}新聞熱點
疑難解答