Page 1 of 1

10473 Simple Base Conversion

Posted: Mon Feb 27, 2017 4:05 pm
by matthewagent
Hi,guys!
I'm recently working on problem 10473 Simple Base Conversion
But no matter how I debug, the code won't work ....
Can't anyone tell me what the problem is? Thanks!!

Code: Select all

#include <iostream>
//the library for string stream
#include <sstream>
#include <cstdio>
using namespace std;

int main() {
	
	string str;
	while (cin >> str) {

		
		
		if (str[0] == '-') {
			break;
		}


		else if (str[1] == 'x') {//means the input is hex
			
			stringstream ss_1;
			long long number_1;
			string string_convert;
			
			for (int i = 2;i <= str.size();i++) {
				string_convert[i] = str[i];
			}
			
			ss_1 << string_convert;
			ss_1 >> number_1;
			cout << dec << number_1 << endl;
		
		}
		else {//means the input is dec
			
			stringstream ss_2;
			long long number_2;
			ss_2 << str;
			ss_2 >> number_2;
			cout << hex << "0x" << number_2 << endl;
		
		}
	}
	return 0;
}


Re: 10473 Simple Base Conversion

Posted: Tue Mar 14, 2017 2:38 pm
by lighted
Check your code here. https://www.udebug.com/UVa/10473