80分求助 WA #4
查看原帖
80分求助 WA #4
121813
老子是北瓜楼主2022/2/8 21:35

我怎么连个模拟都做不对啊……可是我真的看不出有啥问题……

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include <iomanip>
using namespace std;

bool check(unsigned long long x,int len){
	if(x==0) return 0; 
	int len16=0;
	while(len16!=16 && (1ull<<(len16*4) < x) ) 
		++len16;
	if(len16 + 2 > len) return 0;
	return 1; 
}

int main(){
	char c;
	unsigned long long s=0;
	int len=0;
	bool flag=0;
	
	while(cin>>c)
	{
		if('0'<=c && c<='9'){
			s=s*10-'0'+c; ++len;
		}
		else
		{
			if(flag && len!=0){
				if(check(s,len))
					cout<<setiosflags(ios::uppercase)<<"0x"<<hex<<s;
				else
					cout<<dec<<s;
			}
			cout<<c;
			flag=1;
			if(c=='}') flag=0;
			len=0;
			s=0;
		}
	}
	return 0;
}
2022/2/8 21:35
加载中...