小學(xué)生算術(shù)
時(shí)間限制:3000 ms | 內(nèi)存限制:65535 KB 難度:1 描述 很多小學(xué)生在學(xué)習(xí)加法時(shí),發(fā)現(xiàn)“進(jìn)位”特別容易出錯(cuò)。你的任務(wù)是計(jì)算兩個(gè)三位數(shù)在相加時(shí)需要多少次進(jìn)位。你編制的程序應(yīng)當(dāng)可以連續(xù)處理多組數(shù)據(jù),直到讀到兩個(gè)0(這是輸入結(jié)束標(biāo)記)。 輸入 輸入兩個(gè)正整數(shù)m,n.(m,n,都是三位數(shù)) 輸出 輸出m,n,相加時(shí)需要進(jì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; //百位數(shù) int b=n/10%10; //十位數(shù) int c=n/100; //個(gè)位數(shù) int d=m%10; //百位數(shù) int e=m/10%10; //十位數(shù) int f=m/100; //個(gè)位數(shù) 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;}新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注