1. 程式人生 > >zcmu--1108: 鬆哥的困惑【strstr()函式】

zcmu--1108: 鬆哥的困惑【strstr()函式】

Description

都到世界末日了,鬆哥都沒找到女朋友,因此鬆哥感到很困惑.沒想到到了世界末日都沒人喜歡我.鬆哥一生氣就釋出了徵友啟事,第二天,一共有n個人報名應徵鬆哥女友.鬆哥對女友的要求有三點,第一點,名字必須有三個字,第二點,名字中要帶Li,第三點名字中要帶Ting.鬆哥希望你能從n個人中.鬆哥決定選取一人並和她約會.你能找到是誰嘛?

Input

多組測試資料.

每組測試資料的第一行是一個正整數(n<=100).

接下來n行分別有n個名字.每個名字不超過20個字元.

名字的格式為:名+姓,且首字母大寫,比如沈利鬆就叫LiSongShen.

Output

對於每組資料輸出與鬆哥約會的名字.

輸入資料保證只有一個人滿足鬆哥的要求.

Sample Input

2 LiSongShen LiTingXu

Sample Output

LiTingXu

解題思路:靈活運用strstr()函式,這題就so easy。

#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	char l[]="Li";
	char t[]="Ting";
	char s[25];
	while(~scanf("%d",&n))
	{
		for(int i=0;i<n;i++)
		{
			scanf("%s",s);
			int len=strlen(s);
			int count=0;
			for(int i=0;i<len;i++)
			{
				if(isupper(s[i])) count++;
			}
			if(count!=3) continue;
			if(strstr(s,l)!=0&&strstr(s,t)!=0)
			{
				cout<<s<<endl;
			}
		}
	}
	return 0;
}