Animate

/*浙江工业大学 1017
Animate
Time Limit:1000MS  Memory Limit:32768K


Description:
Have you ever Googled the “Animate”?Tyr Googles the “Animate” one day, and find out 245 match records.
But he don’t know whether the number 245 is correct or not. Here comes the problem A: Give you a
documentation,your task is to find out whether this documentation contains the word “Animate” or not.

Input:
The input will consist of several case of input.The first line is an integer N which give the case number.
The next part has N cases.Every case follows this format: Line 1: The beginning of the documentation: #Doc
Line 2 to m-1: The contest of documentation,this may be consists of several lines.Every line contains less
than 100 characters,and the total characters of one documentation is less than 1000. Line m:The end of the
documentation:#End
Output:
For each input case,your program should print an anwser in a single line.If the documentation contains
“Animate”, please print “Yes”, else print “No”. In Google, we know the match is case insensitive,
which means “animate” is also a match of “Animate”. In this problem we just take care of the alphabet
characters, please ignore other characters.

*/
    最开始,这道题我一看,非常容易可以用字符串string类的查找方法,如是写了如下的一个程序:

#include<iostream>
#include
<string>
using namespace std;

int main()
{
    
char tmp[101];
    
string str;
    
int N;
    scanf(
"%d%*c",&N);
    
while(N--){
        
bool flag = false;
        gets(tmp);
        str 
= tmp;
        
while(str!="#END"){
            gets(tmp);
            strupr(tmp);
            str 
= tmp;
            
//cout<<str<<endl;
            if(str.find("ANIMATE")!=4294967295){
                flag 
= true;
            }

        }

        
if(flag){
            cout
<<"Yes"<<endl;
        }
else{
            cout
<<"No"<<endl;
        }

    }

    
return 0;
}

    结果提交的结果,为wrong answear,百思不得其解,如是在网上搜了一下,发现题目的最后一句话:只考虑字母的情况!!这句话才是解这道题目的关键。正确的代码如下所示:

#include<iostream>
#include
<fstream>
#include
<sstream>
using namespace std;
//-----------------------------------
int main(){
    
int a;cin>>a;
    
for(int i=0;i<a;i++){
        
bool isyes=0;
        
string s;bool head=0;
        
string s2="";
        
while(s!="#End"){
            getline(cin,s);
            
if(s=="#Doc")
                head
=1;
            
if(head){
                
for(int i=0;i<s.length();i++)
                    
if(isalpha(s[i]))
                        s2
+=tolower(s[i]);
                
if(s2.find("animate")!=-1 && isyes==0){
                    cout
<<"Yes"<<endl;
                    isyes
=1;
                }

            }

        }

        
if(isyes==0)
            cout
<<"No"<<endl;
    }

}



 

posted on 2012-05-18 21:48 DGQKing 阅读(275) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2012年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜