Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

水题,要用龍龍int

Posted by KatrineYang at 2016-09-12 12:00:48 on Problem 1331
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		vector<int> digitA, digitB, digitC;
		int mxDigit = 0;
		while(a > 0){
			int A = a%10;
			digitA.push_back(A);
			if(A > mxDigit) mxDigit = A;
			a/=10;
		}
		while(b > 0){
			int B = b%10;
			digitB.push_back(B);
			if(B > mxDigit) mxDigit = B;
			b/=10;
		}
		while(c > 0){
			int C = c%10;
			digitC.push_back(C);
			if(C > mxDigit) mxDigit = C;
			c/=10;
		}
		int wsA = digitA.size(), wsB = digitB.size(), wsC = digitC.size();
		bool get = 0;
		for(int BB = mxDigit+1; BB <= 16; BB++){
			long long int aa = 0, bb = 0, cc = 0;
			for(int j = wsA-1; j >= 0; j--){
				aa*=BB;
				aa+=digitA[j];
			}
			for(int j = wsB-1; j >= 0; j--){
				bb*=BB;
				bb+=digitB[j];
			}
			for(int j = wsC-1; j >= 0; j--){
				cc*=BB;
				cc+=digitC[j];
			}
			if(aa*bb==cc){
				get = 1;
				printf("%d\n", BB);
				break;
			}
		}
		if(!get){
			printf("0\n");
		}
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator