2012年5月18日

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 @ 2012-05-18 21:48 DGQKing 阅读(264) | 评论 (0)编辑 收藏

2012年5月7日

Sum It Up

     摘要: /*浙江工业大学1100Sum It Up Time Limit:1000MS  Memory Limit:32768K Description:Given a specified total t and a list of n integers, find all distinct sums using numbers from the list that add up to t. ...  阅读全文

posted @ 2012-05-07 12:48 DGQKing 阅读(381) | 评论 (0)编辑 收藏

2011年11月10日

整数次幂取模

浙江工业大学1052
整数次幂取模
Time Limit:1000MS  Memory Limit:32768K


Description:
给定一个数,其值用A的B次方表示(B<100000),求该数除以一个整数C(<100000)所得的余数。注意算法的合理性,其性能有一定的要求。每行有三个数,依次表示A,B,C,每行对输出对应的余数。

Sample Input:
1 2 3
2 1 3
3 3 5
Sample Output:
1
2
2

源代码:
#include<iostream>
using namespace std;

long power(long A,long B,long C)
{
    
if(B==0){
        
return 1;
    }

    
if(B==1){
        
return A%C;
    }


    
long tmp = power(A,B/2,C);
    
if(B&1==1){
        
return (((tmp*tmp)%C)*(A%C))%C;
    }
else{
        
return (tmp*tmp)%C;
    }

    
return 0;
}


int main()
{
    
long A,B,C;
    
while(scanf("%ld%ld%ld",&A,&B,&C)!=EOF){
        printf(
"%ld\n",power(A,B,C));
    }

    
return 0;
}



/*long long PowerMod(long long a, int b, int k)  
{   //(a^b )%k   
    long long tmp = a, ret = 1;  
    for(; b ; b>>1 )  
    {  
        if (b & 1)  
            ret = (ret * tmp) % k;  //只是每步运算的时候都取模   
        tmp = (tmp * tmp) % k;  
    }  
    return ret;  
}
*/



posted @ 2011-11-10 16:59 DGQKing 阅读(360) | 评论 (0)编辑 收藏

折纸游戏

     摘要: /*浙江工业大学1016折纸游戏 Time Limit:1000MS  Memory Limit:32768K Description:fans喜欢玩折纸游戏。整张纸被分成m*m个格子,即构成一个方阵,每个格子里面都写了一个正整数。游戏分两步:首先左右对折,如果对应的格子的数字都相同,那么进行下一步操作;否则停止游戏,此时游戏的结果是“no”。然后上下对折,如果...  阅读全文

posted @ 2011-11-10 16:16 DGQKing 阅读(780) | 评论 (0)编辑 收藏

简单的事情

题目描述:

简单的事情
Time Limit:1000MS  Memory Limit:32768K


Description:
数学天才fans曾经说过一句话:组合数的计算是一件非常简单的事情。组合数的计算真的是一件非常简单的事情吗?请你自己去尝试一下吧!

Input:
输入中的一些整数对n,m(m≤n≤20)
Output:
输出其组合数。
Sample Input:
5 2
18 13
Sample Output:
10
8568


解题思路:c[n][m] = c[n-1][m-1]+c[n-1][m];

源代码:
#include<iostream>
using namespace std;

int c[21][21];

int main()
{
    
int n,m;
    
for(int i=0;i<=20;i++){
        c[i][
0= 1;
    }

    
for(int i=1;i<=20;i++){
        c[i][i] 
= 1;
    }

    
for(int i=2;i<=20;i++){
        
for(int j=1;j<i;j++){
            c[i][j] 
= c[i-1][j-1]+c[i-1][j];
        }

    }


    
while(scanf("%d%d",&n,&m)!=EOF){
        printf(
"%d\n",c[n][m]);
    }

    
return 0;
}


posted @ 2011-11-10 15:48 DGQKing 阅读(469) | 评论 (0)编辑 收藏

2011年10月5日

C库函数

     摘要: C库函数手册(2007-6-17 15:40:00) 分类函数,所在函数库为ctype.hint isalpha(int ch)  若ch是字母('A'-'Z','a'-'z')返回非0值,否则返回0int isalnum(int ch)  若ch是字母('A'-'Z','a'-'z')或数字('0'-'9')     &...  阅读全文

posted @ 2011-10-05 10:32 DGQKing 阅读(261) | 评论 (0)编辑 收藏

仅列出标题  
<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

导航

统计

常用链接

留言簿

随笔档案

搜索

最新评论

阅读排行榜

评论排行榜