暴力80pts求助
查看原帖
暴力80pts求助
252078
Query_Failed楼主2021/2/7 23:03

暴力拿了80分,不知道哪里错了,求大佬帮助一下,感激不尽!

附上代码:

#include <iostream>
using namespace std;
int main()
{
	char a;
	cin>>a;
	string x;
	cin>>x;
	int r=0,g=0,b=0;
	if('A'<=x[0] and x[0]<='Z') r+=(x[0]-'A'+10)*16;
	else r+=(x[0]-'0')*16;
	if('A'<=x[1] and x[1]<='Z') r+=x[1]-'A'+10;
	else r+=x[1]-'0';
	
	if('A'<=x[2] and x[2]<='Z') g+=(x[2]-'A'+10)*16;
	else g+=(x[2]-'0')*16;
	if('A'<=x[3] and x[3]<='Z') g+=x[3]-'A'+10;
	else g+=x[3]-'0';
	
	if('A'<=x[4] and x[4]<='Z') b+=(x[4]-'A'+10)*16;
	else b+=(x[4]-'0')*16;
	if('A'<=x[5] and x[5]<='Z') b+=x[5]-'A'+10;
	else b+=x[5]-'0';
	
	cout<<a;
	r=255-r;
	g=255-g;
	b=255-b;
	if(r<10) cout<<"0"<<r;
	else if(r<16) cout<<" "<<char(r-10+'A');
	else
	{
		int r2=r%16,r1=(r-r2)/16;
		if(r1<10) cout<<r1;
		else cout<<char(r1-10+'A');
		if(r2<10) cout<<r2;
		else cout<<char(r2-10+'A');
	}
	
	if(g<10) cout<<"0"<<g;
	else if(g<16) cout<<" "<<char(g-10+'A');
	else
	{
		int g2=g%16,g1=(g-g2)/16;
		if(g1<10) cout<<g1;
		else cout<<char(g1-10+'A');
		if(g2<10) cout<<g2;
		else cout<<char(g2-10+'A');
	}
	
	if(b<10) cout<<"0"<<b;
	else if(b<16) cout<<" "<<char(b-10+'A');
	else
	{
		int b2=b%16,b1=(b-b2)/16;
		if(b1<10) cout<<b1;
		else cout<<char(b1-10+'A');
		if(b2<10) cout<<b2;
		else cout<<char(b2-10+'A');
	}
	return 0;
}

2021/2/7 23:03
加载中...