判断闰年 (经典水题)
Problem:250
Time Limit:1000ms
Memory Limit:65536K
Description
输入1个年,请判断是否为闰年。
Input
输入数据有多组,每组1行,就1个数N( 100 < N < 1000000000).
Output
对于每组数据,如果是闰年,输出"yes",否则输出"no",输出结束后要换行。
Sample Input
2012
500
Sample Output
yes
no
Hint
本题5分
Source
c++程序设计
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a;
while(cin>>a)
{
int k=0;
if(a%400==0||a%4==0&&a%100!=0)
{
cout<<"yes"<<endl;
}
else
cout<<"no"<<endl;
}
return 0;
}
搜索字符串
Problem:275
Time Limit:1000ms
Memory Limit:65536K
Description
搜索字符串
Input
输入两个字符串a,b(字符串长度不超过1000)
Output
输出在a中出现b的次数(每个结果占一行)
Sample Input
abcdefsdabcbacbbc
abc
aabbaabbaabbaa
abbaa
Sample Output
2
3
Hint
Source
#include <stdio.h>
#include <string.h>
int main()
{
char a[1001],b[1001];
int t,cnt,flag;
while(scanf("%s%s",a,b)!=-1)
{
cnt=0;
for(int i=0;i<strlen(a);i++)
{
if(a[i]==b[0])
{
t=i;flag=0;
for(int j=1;j<strlen(b);j++)
{
if(a[++t]!=b[j])
{flag=1;break;}
}
if(flag==0)cnt++;
}
}
printf("%d\n",cnt);
}
return 0;
}
这样一直不对,搞不懂
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a[2000],b[2000];
int ans,k,t;
while(cin>>a>>b)
{
ans=0;
for(int i=0;i<strlen(a);i++)
{
if(a[i]==b[0])
{
k=i;
t=0;
for(int j=1;j<strlen(b);j++)
{
if(a[k++]!=b[j]) {t=1;break;}
}
if(t==0) ans++;
}
}
cout<<ans<<endl;
}
return 0;
}
水仙花数
Problem:419
Time Limit:1000ms
Memory Limit:65536K
Description
春天是鲜花的季节,水仙花就是其中最迷人的代表,数学上有个水仙花数,他是这样定义的:
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=13+53+3^3。
现在要求输出所有在m和n范围内的水仙花数。
Input
输入数据有多组,每组占一行,包括两个整数m和n(100<=m<=n<=999)。
Output
对于每个测试实例,要求输出所有在给定范围内的水仙花数,就是说,输出的水仙花数必须大于等于m,并且小于等于n,如果有多个,则要求从小到大排列在一行内输出,之间用一个空格隔开;
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Sample Input
100 120
300 380
Sample Output
no
370 371
Hint
Source
hdu
#include <bits/stdc++.h>
using namespace std;
int main()
{
int m,n,x,y,z,max;
while(cin>>m>>n)
{
int t=0;
for(int i=m;i<=n;i++)
{
x=i/100;
y=(i%100)/10;
z=i%10;
if(i==pow(x,3)+pow(y,3)+pow(z,3))
{
t++;max=i;
}
}
if(t==0) printf("no\n");
else
{
for(int i=m;i<max;i++)
{
x=i/100;
y=(i%100)/10;
z=i%10;
if(i==pow(x,3)+pow(y,3)+pow(z,3))
printf("%d ",i);
}
printf("%d\n",max);
}
}
return 0;
}