【发布时间】:2016-10-31 10:26:14
【问题描述】:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
void main() {
int a, b;
while (cin >> a) {
switch (a) {
case 2: {
cin >> b;
std::string s = std::to_string(b);
int dec = std::stoi(s, nullptr, 2);
cout << dec << endl;break;
}
case 8:
cin >> b;
cout << oct <<b<< endl; break;
case 16:
std::cin >> std::hex >> b;
std::cout << b << std::endl;
}
}
}
那是我的代码。它们每个都可以工作,但十六进制的。当我使用它一次时,它就不起作用了。
For example if i have an input:
2 1111
16 F
8 1
it should have an output:
15
15
1
第一个数字是 hex/bin/oct,第二个是你给的数字。
关于while(cin>>a),是这样的,因为它应该是一个无限循环,会有很多输入,是的。我猜因为那个语句它不起作用,但我不知道不知道怎么解决。
【问题讨论】: