【Nowcoder 7606A】面试

题目:

链接

题目大意:

给一个可能包含 "ABCD" 的字符串,有一个 D 或两个 C 输出 ( exttt{failed}),不然若有三个 A 输出 ( exttt{sp offer}),否则输出 ( exttt{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;
}
原文地址:https://www.cnblogs.com/GJY-JURUO/p/13853758.html