第一题
题目:
代码:
#include<iostream>
#include<cstdio>
using namespace std;
class Date
{
public:
int year;
int month;
int day;
int calculation(int judge,int month,int day);
};
int Date::calculation(int judge,int month,int day)
{
int result=0;
result=(month-1)*31+day;
if(month>2)
{
if(judge==1) //如果是闰年
{
result=result-(month/2)-2;
}
else
{
result=result-(month/2)-1;
}
}
return result;
}
int main()
{
Date date1;
int year1,month1,day1,decide,number;
while(scanf("%d %d %d",&year1,&month1,&day1)!=EOF)
{
decide=0;
if(year1==0 && month1==0 && day1==0)
{
break;
}
else
{
if(year1%4==0&&year1%100!=0||year1%400==0)
{
decide=1;
}
number=date1.calculation(decide,month1,day1);
cout<<number<<endl;
}
}
return 0;
}
第二题
题目:
代码
#include<iostream>
#include<cstring>
#include <string>
#include<cstdio>
#include<algorithm>
using namespace std;
class Students
{
private:
int room;
string name;
int height;
int weight;
public:
void begin()
{
height = 0;
}
void getin(string a,int b,int c,int d)
{
if(b>height)
{
room=d;
name=a;
height=b;
weight=c;
}
}
void print()
{
printf("%06d ",room);
cout<<name<<" "<<height<<" "<<weight<<endl;
}
int ad()
{
if(height!=0)
return 0;
else
return 1;
}
}student[1000000];
int a[1000000];
int main()
{
int n,i,j=0;
cin>>n;
for(i=0;i<n;i++)
{
int room,height,weight;
string name;
cin>>room>>name>>height>>weight;
a[j]=room;
j=j+student[room].ad();
student[room].getin(name,height,weight,room);
}
sort(a,a+j);
for(i=0;i<j;i++)
{
student[a[i]].print();
}
return 0;
}
第三题
题目:
代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int num[100000][1000];
int main()
{
int begin,end,i,n,m,x,y,how=0,how1=0,result=0;
cin>>begin>>end;
for(n=begin;n<=end;n++)
{
how=0;
m=sqrt(n);
for(i=1;i<=m;i++)
{
x=n%i;
if(x==0)
{
y=n/i;
num[n][how]=i;
how++;
if(i!=y)
{
num[n][how]=y;
how++;
}
}
}
if(how>how1)
{
how1=how;
result=n;
}
}
sort(num[result],num[result]+how1);
cout<<"["<<begin<<","<<end<<"] ";
cout<<result<<" "<<how1<<endl;
for(i=0;i<how1-1;i++)
{
cout<<num[result][i]<<" ";
}
cout<<num[result][i];
return 0;
}
第四题
题目:
代码
#include<iostream>
#include<cstdio>
#include<stdlib.h>
using namespace std;
struct Node
{
int data;
struct Node *next;
};
int main()
{
Node *change(Node *head);
int repeat;
cin>>repeat;
for(int i=0;i<repeat;i++)
{
int n;
Node *head,*p1,*p2;
head=NULL;
p2=(Node*)malloc(sizeof(Node));
while(scanf("%d",&n)!=EOF)
{
p1=(Node*)malloc(sizeof(Node));
if(n==-1)
{
p2->next=NULL;
break;
}
else
{
p1->data=n;
if(head == NULL) /*如果是开头的话*/
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
}
}
/*到这里没问题*/
head=change(head); /*删去奇数的节点*/
if(head != NULL) /*输出*/
{
while(head->next != NULL)
{
cout<<head->data<<" ";
head=head->next;
}
cout<<head->data<<endl;
}
}
return 0;
}
Node *change(Node *head)
{
Node *p1,*p2;
while(head!=NULL && head->data%2 != 0)
{
head=head->next;
}
p1=p2=head;
if(head==NULL)
return head;
p1=p1->next;
while(p1 != NULL)
{
if(p1->data%2 != 0)
{
while(p1!=NULL && p1->data%2 != 0)
{
p1=p1->next;
}
p2->next=p1;
}
else
{
p2=p1;
p1=p1->next;
}
}
return head;
}
第五题(与第四题相同,就不贴代码了)
题目:
这一系列下来的收获: