【Nowcoder 7606A】面试

题目:

链接

题目大意:

给一个可能包含 "ABCD" 的字符串,有一个 D 或两个 C 输出 \(\texttt{failed}\),不然若有三个 A 输出 \(\texttt{sp offer}\),否则输出 \(\texttt{offer}\)

代码:

int n;
string s;

int main()
{
	for (scanf ("%d", &n); n--; )
	{
		cin >> s;
		int a, b, c, d;
		a = b = c = d = 0;
		for (int i = 0; i < s.size(); ++i)
		{
			if(s[i] == 'A') a++;
			if(s[i] == 'B') b++;
			if(s[i] == 'C') c++;
			if(s[i] == 'D') d++;
			if (d) break;
			if (c >= 2) break;
		}
		if(d || c >= 2) {puts("failed"); continue;}
		if (a >= 3) puts("sp offer"); else puts("offer");
	}
	return 0;
}
posted @ 2020-10-21 17:42  Jayun  阅读(129)  评论(0编辑  收藏  举报