c++程序题求解

用函数




米琪卡哇伊
浏览 727回答 1
1回答

慕仙森

using namespace std;&nbsp;int to10bit(int x, int B){&nbsp; &nbsp; int bit;&nbsp; &nbsp; int res = 0, k = 1;&nbsp; &nbsp; while( x != 0 ){&nbsp; &nbsp; &nbsp; &nbsp; bit&nbsp; = x%10;&nbsp; &nbsp; &nbsp; &nbsp; res += bit*k;&nbsp; &nbsp; &nbsp; &nbsp; k *= B;&nbsp; &nbsp; &nbsp; &nbsp; x /= 10;&nbsp; &nbsp; }&nbsp; &nbsp; return res;}&nbsp;int main(){&nbsp; &nbsp; int x, y, z;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; while( cin >> x >> y >> z )&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; int p, q, r;&nbsp; &nbsp; &nbsp; &nbsp; int B;&nbsp; &nbsp; &nbsp; &nbsp; for(B = 2; B <= 40; ++B){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = to10bit(x, B);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; q = to10bit(y, B);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; r = to10bit(z, B);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if( p*q == r ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout << B << endl;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if( B > 40 ){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cout << "0" << endl;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; return 0;}
打开App,查看更多内容
随时随地看视频慕课网APP