代码有注释90分WA#8#19求助
查看原帖
代码有注释90分WA#8#19求助
195331
Mine_KingCattleya楼主2021/6/19 22:02

RtΔRt\Delta#8\#8 是应该输出E我输出W#19\#19 是输出过短,求大佬查错kel
万分感谢!

#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
char ch;//读入
string s;//存每个单元的类型,即101,111,0或者其他的什么会Error的东西
bool flag;//flag=true表示上一个是数
int numx,tot,types[100005],ans[100005];
//numx表示上一个数
//tot是输出的数量
//types[i]是第i个输出的类型,1表示大写字母,2表示空格,3表示数
//ans[i]表示:当types=0时输出'A'+ans[i];当types=3时输出ans[i]
int main()
{
	while(true)
	{
		s="";
		int num=0;
		for(int i=1;i<=8;i++)//读入一个单元
		{
			ch=getchar();
			if(ch==EOF||ch==' '||ch=='\r'||ch=='\n')//碰到结尾字符
			{
				if(i==1) goto BREAK;//处理结束
				else goto ERROR;//否则就是Error
			}
			if(ch!='0'&&ch!='1') goto ERROR;//出现非0/1的字符
			if(i>3||s=="0") num=num*2+ch-'0';//存单元的后面几位
			else s+=ch;//存前面类型
		}
		if(s=="100"||s=="110") goto ERROR;//不符合条件,Error
		if(s=="101")//字母
		{
			if(num>25) goto ERROR;//比'Z'还大,Error
			types[++tot]=1;
			ans[tot]=num;
		}
		if(s=="111") types[++tot]=2;
		if(s=="0")
		{
			if(flag==true)//这是第二个数
			{
				types[++tot]=3;
				ans[tot]=numx+num/2;//存答案
				numx=0;flag=false;//清空
			}
			else numx=num/2,flag=true;//标记
		}
	}
	BREAK:
	for(int i=1;i<=tot;i++)
		if(types[i]==1) printf("%c",ans[i]+'A');
		else if(types[i]==2) printf(" ");
		else printf("%d",ans[i]);
	//输出
	return 0;
	ERROR:
	puts("Error");
	return 0;
	//Error部分
}
2021/6/19 22:02
加载中...