杭电oj第几天c(杭电OJ问题(2005题))

本文目录
- 杭电OJ问题(2005题)
- 杭电oj2005----一年的第几天问题
- 杭电oj1004 Let the Balloon RIse
- 拜托C语言大神/(ㄒoㄒ)/~~杭电oj1002
- 杭电OJ问题
- C++ 杭电oj上的1084运行一点问题都没有,就是不能通过,求高手帮忙
杭电OJ问题(2005题)
给你一个测试用例:
2001/3/1
2000/3/1
2001/3/1
你输出的结果是:
60
61
61
因为在第二个值即2000闰年的时候,你把feb赋成了29,第三个值2001不是闰年,却还是用的29天。你增加 else feb=28; 这一句就好了。
#include《stdio.h》
int main()
{
int year,month,day,date,jun=31,feb=28,mar=31,apr=30,may=31,liu=30,jul=31,aug=31,jiu=30,oct=31,nov=30;
while(scanf("%d/%d/%d",&year,&month,&day)!=EOF)
{
if((year%4==0&&year%100!=0)||(year%400==0))feb=29;
else feb=28; //增加这一行
//printf("now jun=%d,feb=%d,dayËÑË÷=%d\n",jun,feb,day);
if(month==1) date=day;
else if(month==2) date=jun+day;
else if(month==3) date=jun+feb+day;
else if(month==4) date=jun+feb+mar+day;
else if(month==5) date=jun+feb+mar+apr+day;
else if(month==6) date=jun+feb+mar+apr+may+day;
else if(month==7) date=jun+feb+mar+apr+may+liu+day;
else if(month==8) date=jun+feb+mar+apr+may+liu+jul+day;
else if(month==9) date=jun+feb+mar+apr+may+liu+jul+aug+day;
else if(month==10) date=jun+feb+mar+apr+may+liu+jul+aug+jiu+day;
else if(month==11) date=jun+feb+mar+apr+may+liu+jul+aug+jiu+oct+day;
else if(month==12) date=jun+feb+mar+apr+may+liu+jul+aug+jiu+oct+nov+day;
printf("%d\n",date);
}
return 0;
}
杭电oj2005----一年的第几天问题
这是我的代码,你看看。。
#include《stdio.h》
void main()
{
int y,m,d,sum,i;
int month={0,31,28,31,30,31,30,31,31,30,31,30,31};
while((scanf("%d/%d/%d",&y,&m,&d))!=EOF)
{
sum=d;
if(y%4==0&&y%100!=0||y%400==0)
month=29;
else
month=28;
for(i=1;i《m;i++)
sum+=month;
printf("%d\n",sum);
}
}
杭电oj1004 Let the Balloon RIse
#include 《stdio.h》
#include 《string.h》
main(){
freopen("x.in","r",stdin);
int n, i, j, t, max, num表示的是i之后有多少和i颜色相同的气球
char color;
while(scanf("%d", &n) != EOF){
if(n){
num=0;
scanf("%s", color);
for(i=1; i 《n; i++){
num=0;
scanf("%s", color);
for(j=0;j《i;j++) //这里应该是枚举i之前的所有的,不应该是《i-1,而是《i,能AC大概是人品好吧....
if(strcmp(color)==0)
num+=1;
}
max=num;
t=0;
for(i=1;i《n;i++)
if(max《num){
max=num;
t=i;
}
printf("%s\n",color);
}
}
}
拜托C语言大神/(ㄒoㄒ)/~~杭电oj1002
Sum函数有逻辑错误:
1.while(a!=’*’){//按你的进位处理思路应该改如下:
//sum-’0’;
sum-’0’;//要改成这样
if(sum》’9’){
sum=’1’;
sum-10;
}
else sum原是’*’
n--;
}
2.if(a!=’*’){
while(a!=’*’){//这段只有遇到一次无进位后才不会再有进位
//sum;
sum有可能是’1’
if(sum是’9’时
sum=’1’;
sum-10;
}
else sum=’0’;//道理同前述
}
n--;
}
3.if(b!=’*’){...一段要做与2一样的处理。
思路正确,但实现复杂了……供参考。
杭电OJ问题
#include 《stdio.h》
int main(int argc, char *argv)
{
int a = { 0, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int b = { 0, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int q, w, e, sum = 0, i;
while (scanf("%d/%d/%d", &q, &w, &e) != EOF)
{
sum = 0; // 重设为0
if ((q % 4 == 0 && q % 100 != 0) || (q % 400 == 0))
{
for (i = 0; i《w; i++)
sum += a;
}
else
{
for (i = 0; i《w; i++)
sum += b;
}
printf("%d\n", sum + e);
}
return 0;
}
C++ 杭电oj上的1084运行一点问题都没有,就是不能通过,求高手帮忙
#include《iostream》
#include《vector》
#include《algorithm》
#include《string》
using namespace std;
struct member
{
int num;
int time;
}Member;
bool operator《(member a, member b)
{
return a.time 《 b.time;
}
int score;
void main()
{
void mysort(vector 《member》 m,int S);
int n;
string str;
int p;
int h;
int m;
int s;
int i;
while(cin》》n&&n》=0)
{
vector 《member》 rank4;
vector 《member》 rank3;
vector 《member》 rank2;
vector 《member》 rank1;
for(i=0;i《n;i++)
{
cin》》p》》str;
if(p==5){score=100;continue;}
if(p==0){score=50;continue;}
sscanf(str.c_str(),"%d:%d:%d",&h,&m,&s);
s=h*3600+m*60+s;
Member.time=s;
Member.num=i;
if(p==4)
{
rank4.push_back(Member);
score=90;
}
if(p==3)
{
rank3.push_back(Member);
score=80;
}
if(p==2)
{
rank2.push_back(Member);
score=70;
}
if(p==1)
{
rank1.push_back(Member);
score=60;
}
}
mysort(rank4,95);
mysort(rank3,85);
mysort(rank2,75);
mysort(rank1,65);
for(i=0;i《n;i++)
cout《《score《《endl;
cout《《endl;
memset(score,0,sizeof(score));
}
}
void mysort(vector 《member》 m,int S)
{
int i;
int j;
int k;
if(m.size()==1)
{
score=S;
return;
}
sort(m.begin(),m.end());
for(i=0;i《m.size()/2;i++)
{
score = S;
}
}

更多文章:
国内教python最好的老师(全国排名前三的Python培训是哪些)
2026年10月16日 00:30
skimming(Scanning和Skimming的区别是什么)
2026年10月15日 22:30
orderby是什么功能(在sql语句中,ORDERBY子句的功能是())
2026年10月15日 20:20
整型数组初始化为0(c语言 定义一个5*5个元素整型数组,所有元素初始化为0;从键盘输入5*5个元素到该数组,求数)
2026年10月15日 12:20






