1. 程式人生 > 其它 >CF312A Whose sentence is it? 題解

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;
}