10473 Simple Base Conversion

All about problems in Volume 104. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Post Reply
New poster
Posts: 2
Joined: Sat Feb 25, 2017 7:18 pm

10473 Simple Base Conversion

Post by matthewagent »

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] == '-') {

		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;

Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10473 Simple Base Conversion

Post by lighted »

Check your code here. https://www.udebug.com/UVa/10473
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 104 (10400-10499)”