| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1020 人关注过本帖
标题:[求助]一道ACM题目
只看楼主 加入收藏
hacker168
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-10-18
收藏
 问题点数:0 回复次数:7 
[求助]一道ACM题目

Input


The input consists of T test cases. The number of T is given on the first line of the input file.Following T lines, which represent dates, one date per line. The format for a date is "month day" where month is a number between 1 (which indicates January) and 12 (which indicates December), day is a number between 1 and 31.All the date in the input are in 2006, you can assume that all the dates in the input are legal(合法).


Output


For each case, if the date is before Octorber 21st, you should print a number that between the date and Octorber 21st.If the day is beyond Octorber 21st, just print "What a pity, it has passed!".If the date is just Octorber 21st, print"It's today!!".

Sample Input


7
10 20
10 19
10 1
10 21
9 1
11 11
12 12
Sample Output


1
2
20
It's today!!
50
What a pity, it has passed!
What a pity, it has passed!

搜索更多相关主题的帖子: ACM 
2006-10-18 14:02
huanguyu
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-4-26
收藏
得分:0 

#include <iostream>
using namespace std;

struct data //存放日期数据的结构
{
int nMon; //月份
int nDay; //日
};

void compute(int);

int main()
{
int nk;
cin>>nk;
compute(nk);
return 0;
}

void compute(int nx)
{
int* array=new int [nx]; //用于保存输入日期和10月21日的差距的数组
for (int i=0; i<nx; i++) //读入 nx 组 日期
{
data temp;
cin>>temp.nMon>>temp.nDay;
int nDis;
nDis=(10-temp.nMon)*31+(21-temp.nDay); //求出和10月21日的差距
if (0 > nDis)
array[i] = -1; //在10月21日之后的 保存为-1
else
array[i] = nDis; //其他的保存为差距
}

for (int nTemp=0; nTemp < nx; nTemp++)
{
if ( -1 == array[nTemp]) //10月21日后的
{
cout<<"What a pity, it has passed!"<<endl;
}
else if ( 0 == array[nTemp] ) //10月21日当天
{
cout<<"It's today!!"<<endl;
}
else
{
cout<<array[nTemp]<<endl; // 10月21日前的
}

}
delete []array;
}



我很郁闷的就是 怎么明明是在21日后的它说 PASSED了?????

[此贴子已经被作者于2006-10-18 14:48:22编辑过]


看越多书就发现自己越无知 于是就越想知道更多
2006-10-18 14:38
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
我很菜,但程序很容易写,只是我不知道ACM是什么东东,楼主解释一下吧

题目是说输入文件中第一行是个整数,表示下面还有几行,后面是每行两个数,第一个数是月份在1-12间,第二个是日期在1-31间。输出:10月21号前的日期输出与这天相差的天数,10月21号后的输出"What a pity, it has passed!".是10月21号就输出"It's today!!" 只是简单的比较、选择、输出。 ACM是什么意思,是不是有特殊要求??

其实我也很无聊!
2006-10-18 14:52
hacker168
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-10-18
收藏
得分:0 
二楼的,有点错误啊!最后结果中输9 1得出的结果应是50 ,而你的是51
2006-10-18 14:56
huanguyu
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-4-26
收藏
得分:0 

我觉的 10月1号和9月1号的差距应该是一个月吧 就是31天 10月1号和10月21的差距是20天 两个一起是否就是51


能否告诉我你是在哪个网址做的ACM 偶想去看看 谢谢

[此贴子已经被作者于2006-10-18 15:09:17编辑过]


看越多书就发现自己越无知 于是就越想知道更多
2006-10-18 15:08
hacker168
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-10-18
收藏
得分:0 
不是啊,9月只有30天的
2006-10-18 15:09
hacker168
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-10-18
收藏
得分:0 

请问二楼的是否要考虑9月是30天,而8月是31天,这样算法就要改了

2006-10-18 15:31
huanguyu
Rank: 1
等 级:新手上路
帖 子:90
专家分:0
注 册:2006-4-26
收藏
得分:0 

抱歉 没看清楚题目

#include <iostream>
using namespace std;

struct Date //存放日期数据的结构
{
int nMon; //月份
int nDay; //日
};
const Date SD={10,21}; //可以改动,因为目前是和10月21号对比,所以采用10,21
/////////////////////////////////////////////////////////

void compute(int);
int nDB(const Date nMon,const Date Mon=SD);//计算2个Date之间的日期差别
//////////////////////////////////////////////////////

int main()
{
int nk;
cin>>nk; //数据组数
compute(nk);
return 0;
}

////////////////////////////////////////////////

void compute(int nx)
{
int* array=new int [nx]; //用于保存输入日期和10月21日的差距的数组
for (int i=0; i<nx; i++) //读入 nx 组 日期
{
Date temp;
cin>>temp.nMon>>temp.nDay;
int nDis=nDB(temp); //求出和10月21日的差距
if (0 > nDis)
array[i] = -1; //在10月21日之后的 保存为-1
else
array[i] = nDis; //其他的保存为差距
}

for (int nTemp=0; nTemp < nx; nTemp++)
{
if ( -1 == array[nTemp]) //10月21日后的
{
cout<<"What a pity, it has passed!"<<endl;
}
else if ( 0 == array[nTemp] ) //10月21日当天
{
cout<<"It's today!!"<<endl;
}
else
{
cout<<array[nTemp]<<endl; // 10月21日前的
}

}
delete []array;
}

////////////////////////////////////////////////////////////
int nDB(const Date m,const Date Mon)
{
int array[12]={31,28,31,30,31,30,31,31,30,31,30,31}; //12个月的天数
int nSum(0); //记录月份间天数差别
for (int i = m.nMon; i < Mon.nMon; i++)
{
nSum+=array[i-1];
}
if ( m.nMon > Mon.nMon)
nSum=-31;
int nDis=nSum+(Mon.nDay-m.nDay); //得到Date间天数差
return nDis; //返回
}

[此贴子已经被作者于2006-10-18 17:18:25编辑过]


看越多书就发现自己越无知 于是就越想知道更多
2006-10-18 16:15
快速回复:[求助]一道ACM题目
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017279 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved