计算两个日期的差值
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
#define ISYEAR(x) (x%100!=0 && x%4==0)|| x%400?0:1
int dayofmonth[13][2]{
0,0,
31,31,
28,29,
31,31,
30,30,
31,31,
30,30,
31,31,
31,31,
30,30,
31,31,
30,30,
31,31,
};
struct date{
int day;
int month;
int year;
void nextday(){
day++;
if(day>dayofmonth[month][ISYEAR(year)]){
day=1;
if(month>12) {
month=1;
year++;
}
}
}
};
int buf[5001][13][32];
int main()
{
date tmp;
int cnt=0;
tmp.year=0;
tmp.month=1;
tmp.day=1;
while(tmp.year!=5001){
buf[tmp.year][tmp.month][tmp.day]=cnt;
tmp.nextday();
cnt++;
}
int d1,m1,y1,d2,y2,m2;
while(scanf("%4d%2d%2d",&d1,&m1,&y1)!=EOF){
scanf("%4d%2d%2d",&d2,&m2,&y2);
printf("%d",abs(buf[d1][m1][y1]-buf[d2][m2][y2]));
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
int n;
while(scanf("%d",&n)!=EOF&&n!=0){
int Hash[101]={0};
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
Hash[x]++;
}
int x;
scanf("%d",&x);
printf("%d\n",Hash[x]);
}
return 0;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
#define OFFSET 500000
int Hash[1000001];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
memset(Hash,0,sizeof(Hash));
for(int i=0;i<n;i++){
int x;
scanf("%d",&x);
Hash[x+OFFSET]=1;
}
for(int i=50000;i<=-500000;i--){
if(Hash[i+OFFSET]){
printf("%d",i);
m--;
if(m) printf(" ");
else {
printf("\n");
break;
}
}
}
}
return 0;
}