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;
}