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

注意0

Posted by KatrineYang at 2016-11-14 11:18:16 on Problem 1546
#include <iostream>
#include <cstring>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

void print(string s){
	int l = s.length();
	if(l>7) cout << "  ERROR"<< endl;
	else{
		for(int i = 0; i < 7-l; i++) cout << " ";
		cout << s << endl;
	}
}

int tI(char c){
	if(c>='0' && c<='9') return c-'0';
	return c-'A'+10;
}

char tC(int i){
	if(i<10) return i+'0';
	return i-10+'A';
}

string cvs(string &s, int o, int n){
	int l = s.length();
	long long int ans=0;
	for(int i = 0; i<l; i++){
		ans *= o;
		ans += tI(s[i]);
	}
	if(ans == 0) return "0";
	string res;
	while(ans>0){
		res=tC(ans%n)+res;
		ans/=n;
	}
	return res;
}

string str;
int o,n;

int main() {
	while(cin >> str >> o >> n){
		print(cvs(str,o,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