Kattis <Simon Says>

来源:互联网 发布:唯品会抢购软件 编辑:程序博客网 时间:2024/05/23 20:01

此文章可以使用目录功能哟↑(点击上方[+])

 Kattis <Simon Says>

Accept: 0    Submit: 0
Time Limit: 1 second    Memory Limit : 1024 MB

 Problem Description

In the game “Simon Says” one person plays the role of Simon, who gives instructions to everyone else playing the game. The tricky part is that if Simon begins his instruction with “Simon says” then everyone else must follow the instruction (or they lose the game); if Simon gives an instruction that does not begin with “Simon says” then everyone is supposed to completely ignore the instruction (or they lose the game)!

Simon tries his or her best to trick the other players into following the wrong instructions. Simon might begin by saying “Simon says touch your nose.” and follow this with “Stop touching your nose.” Anyone who stops touching their nose loses! The last player still remaining, who has correctly followed precisely the instructions that began with “Simon says” (and only these instructions), gets to be Simon next.

As a child, you were horrible at this game. Your older siblings were always able to trick you into following the wrong instructions. Well, you will have the last laugh: now that you are a computer programmer, you can write a computer program that can help you play the game perfectly. You only need to make sure the program is able to determine which instructions to follow and which to ignore.

Are you up to the challenge? Can you craft a computer program that never makes any mistakes in the game? If you can, then surely fame and glory shall come your way for being the most unstoppable player of Simon Says ever!

 Input

Input starts with a line containing an integer 1≤N≤1000. Each of the next N lines is one command, of length at most100 characters. Each command is a properly-capitalized sequence of one or more words, separated by a single space between each pair of words, ending in a period. Some commands begin with “Simon says” and others may not. If a command begins with “Simon says”, there will always be another space and at least one additional word after “says”. No lines contain leading or trailing space.

 Output

For each line that begins with precisely “Simon says”, output the rest of the line. Each line that does not begin with precisely “Simon says” should be ignored.

 Sample Input

1
Simon says smile.
3
Simon says raise your right hand.
Lower your right hand.
Simon says raise your left hand.
3
Raise your right hand.
Lower your right hand.
Simon says raise your left hand.

 Sample Output

smile.
raise your right hand.
raise your left hand.
raise your left hand.

 Problem Idea

解题思路:

【题意】

一个叫做"Simon Says"的游戏

给你n个字符串

你需要从开头为"Simon says"的字符串中提取出它的后缀(即除去"Simon says"的部分)

其他开头不是"Simon says"的字符串忽略

【类型】
字符串处理

【分析】

因为固定要找开头为"Simon says"的字符串

所以我们可以将每个字符串的前10个字符提取出来

用字符串比较函数strcmp将提取出来的10个字符与"Simon says"进行比较

如果一致,那么该字符串就是我们要的字符串

此时只需要将该字符串从第12个字符(除去"Simon says "这11个字符)开始输出即可

【时间复杂度&&优化】
O(n)

题目链接→Kattis <Simon Says>

 Source Code

/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<bitset>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define PI acos(-1.0)#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 105;const int M = 100005;const int inf = 1000000007;const int mod = 10007;char s[N],ans[11]="Simon says";int main(){    int n;    scanf("%d",&n);    getchar();    while(n--)    {        gets(s);        s[10]='\0';        if(!strcmp(s,ans))            puts(s+11);    }    return 0;}
菜鸟成长记

0 0