其他分享
首页 > 其他分享> > CF312A Whose sentence is it? 题解

CF312A Whose sentence is it? 题解

作者:互联网

Content

\(\texttt{Freda}\) 和 \(\texttt{Rainbow}\) 在网上聊了 \(n\) 句话。我们根据他们聊天的语句的特点来判断每一句是谁说的。\(\texttt{Freda}\) 说的话结尾带有 \(\texttt{lala.}\),而 \(\texttt{Rainbow}\) 说的话开头带有 \(\texttt{miao.}\)。试判断每一句话是谁说的,或者不能确定某些话是谁说的。

数据范围:\(1\leqslant n\leqslant 10\)。

Solution

直接判断前 \(5\) 个字符和后 \(5\) 个字符即可。需要注意的是,如果出现了像样例中的 \(\texttt{miao.}\) 在开头并且 \(\texttt{lala.}\) 在结尾的一句话,则它也是不确定的。

Code

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int n;
string s;

int check1(string s) {
	int len = s.size();
	if(s[len - 1] == '.' && s[len - 2] == 'a' && s[len - 3] == 'l' && s[len - 4] == 'a' && s[len - 5] == 'l')	return 1;
	return 0;
}
int check2(string s) {
	int len = s.size();
	if(s[0] == 'm' && s[1] == 'i' && s[2] == 'a' && s[3] == 'o' && s[4] == '.')	return 1;
	return 0;
}

int main() {
	scanf("%d", &n);
	getchar();	//避免换行被吃掉
	for(int i = 1; i <= n; ++i) {
		getline(cin, s);
		if((check1(s) && check2(s)) || (!check1(s) && !check2(s)))	cout << "OMG>.< I don't know!\n";
		else if(check1(s))	cout << "Freda's\n";
		else if(check2(s))	cout << "Rainbow's\n";
	}
	return 0;
}

标签:Whose,return,string,int,题解,texttt,len,&&,CF312A
来源: https://www.cnblogs.com/Eason-AC/p/15717081.html