样例过了-测试过不了咋办
查看原帖
样例过了-测试过不了咋办
922134
jiejielove楼主2023/3/13 15:17
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include <cstdlib>
#include<stdlib.h>
#include<sstream>
#include<stack>
#include <climits>
using namespace std;


stack <char>stk;
int main()
{
	//八进制转十进制
	string s;
	cin >> s;
	long long p;
	long long q;
	long long sum = 0;
	for (int i = 0; i < s.length(); i++)
	{
		p = s[i] - '0';
		sum = sum + p*pow(8, s.length()-i-1);
	}
	while (sum!= 0)
	{
		q = sum % 16;
		if (q >= 0 && q <= 9)
		{
			stk.push(q+'0');
		}
		else if (q == 10)
		{
			stk.push('a');
		}
		else if (q == 11)
		{
			stk.push('b');
		}
		else if (q == 12)
		{
			stk.push('c');
		}
		else if (q == 13)
		{
			stk.push('d');
		}
		else if (q == 14)
		{
			stk.push('e');
		}
		else if (q == 15)
		{
			stk.push('f');
		}
		sum = sum / 16;
	}
	while (!stk.empty())
	{
		cout << stk.top();
		stk.pop();
	}
	return 0;
}
2023/3/13 15:17
加载中...