提供本题 SPJ
查看原帖
提供本题 SPJ
237530
rzh123楼主2021/12/2 22:44
#include <string>
#include "testlib.h"
using std::string;
int n;
int st[37]={0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0};
int x[13]={6,2,5,5,4,5,6,3,7,6};
int osl;
string IMPSB="Impossible";
string pat1="00:00";
string pat2=IMPSB;
int isnumc(char c){
	return c>='0'&&c<='9';
}
void check_len(int anl){
	if(osl<anl){
		quitf(_wa,"Invalid answer.Your answer is too short.");
	}
	if(osl>anl){
		quitf(_wa,"Invalid answer.Your answer is too long.");
	}
}
void check_pat(string s,string p){
	for(int i=0;i<osl;++i){
		if(p[i]=='0'){
			if(!isnumc(s[i])){
				quitf(_wa,"Invalid answer.On line 1 column %d, read %c, expected a numeric character.",i+1,s[i]);
			}
		}
		else{
			if(s[i]!=p[i]){
				quitf(_wa,"Invalid answer.On line 1 column %d, read %c, expected %c.",i+1,s[i],p[i]);
			}
		}
	}
}
int ok(int a,int b){
	int t=x[a/10]+x[a%10]+x[b/10]+x[b%10];
	return t==n;
}
int main(int argc, char* argv[]) {
	registerTestlibCmd(argc, argv);
	string outs=ouf.readToken();
	n=inf.readInt();
	osl=outs.size();
	if(st[n]){
		check_len(5);
		check_pat(outs,pat1);
		int a=(outs[0]^48)*10+(outs[1]^48),
			b=(outs[3]^48)*10+(outs[4]^48);
		if(a>23){
			quitf(_wa,"Wrong answer.The number %d is too large.",a);
		}
		if(b>59){
			quitf(_wa,"Wrong answer.The number %d is too large.",b);
		}
		if(!ok(a,b)){
			quitf(_wa,"Wrong answer.The number of the segments is wrong.");
		}
	}
	else{
		check_len(10);
		check_pat(outs,pat2);
	}
	quitf(_ok,"The answer is correct.");
}
2021/12/2 22:44
加载中...