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