这次有四题:
题目1:(这题本身没难度,就是听说格式比较坑,好像)
代码:
#include<iostream>
#include<cstdio>
using namespace std;
class Date
{
private:
int year;
int month;
int day;
public:
void display();
void get(int a,int b,int c);
};
void Date::display()
{
printf("%04d/%02d/%02d ",year,month,day);
}
void Date::get(int a,int b,int c)
{
year=a;
month=b;
day=c;
}
class Time
{
private:
int hour;
int minute;
public:
void display();
void get(int a,int b);
};
void Time::display()
{
printf("%02d:%02d",hour,minute);
cout<<endl;
}
void Time::get(int a,int b)
{
hour=a;
minute=b;
}
int main()
{
int a,b,c,d,e;
while(scanf("%d%d%d%d%d",&a,&b,&c,&d,&e)!=EOF)
{
if(a==0 && b==0 && c==0 && d==0 && e==0)
{
break;
}
else
{
Date date1;
Time time1;
date1.get(a,b,c);
time1.get(d,e);
date1.display();
time1.display();
}
}
return 0;
}
题目二:(这题思路上不能错,我是在同学帮助下才知道是怎么求出最大的收益的那天的,本来以为要用递归,结果发现只要两个for就行了)
#include<iostream>
#include<cstdio>
using namespace std;
class gupiao
{
private:
int day[8];
public:
void get_(int days[])
{
for(int i=1;i<=7;i++)
{
day[i]=days[i];
}
}
void print()
{
int max=0,count;
int begin,end;
int i,j;
for(i=1;i<8;i++)
{
count=0;
for(j=i;j<8;j++)
{
count=count+day[j];
if(count>=max)
{
if(count==max && end-begin<=j-i)
continue;
begin=i;
end=j;
max=count;
}
}
}
if(max<=0)
{
cout<<"won't buy!"<<endl;
}
else
{
cout<<max<<" "<<begin<<" "<<end<<endl;
}
}
};
int main()
{
int days[8],i;
while(cin>>days[1]>>days[2]>>days[3]>>days[4]>>days[5]>>days[6]>>days[7])
{
if(days[1]==0 && days[2]==0 && days[3]==0 &&days[4]==0 && days[5]==0 &&days[6]==0 &&days[7]==0)
break;
else
{
gupiao p;
p.get_(days);
p.print();
}
}
return 0;
}
题目三:(B的胜利计算有点坑就是了,是胜利的减去失败的,4:2是4-2,而不是代表赢一场)
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include <cstdlib>
#include<cctype>
#include <sstream>
using namespace std;
class Group
{
protected:
string name;//姓名
int mark;
public:
virtual void display()//显示考核成绩
{
cout<<mark<<endl;
}
};
class GroupA : public Group
{
public:
void get_(string a,int b,int c)
{
name=a;
mark=2*b-c;
}
void print()
{
cout<<name<<" "<<"A ";
}
};
class GroupB : public Group
{
public:
void get_(string s,int d[])
{
mark=0;
name=s;
mark=d[0]+d[2]+d[4]+d[6]+d[8]-d[1]-d[3]-d[5]-d[7]-d[9];
}
void print()
{
cout<<name<<" "<<"B ";
}
};
int main()
{
string a;
while(cin >> a)
{
if(a=="0")
break;
else if(a=="A")
{
GroupA group1;
string s;
int b,c;
cin>>s>>b>>c;
group1.get_(s,b,c);
group1.print();
group1.display();
}
else if(a=="B")
{
stringstream ss;
GroupB group2;
string s1,s2;
int i,j,n,d[10];
cin>>s1;
getchar();
getline(cin,s2,'
');
i=s2.size();
for(j=0;j<10;j++)
{
d[j]=0;
}
string s3=" ";
for(n=0,j=0;n<i;n++)
{
if(s2[n]==':')
{
ss<<s3;
ss>>d[j];
ss.clear();
j++;
s3=" ";
}
else if(isspace(s2[n]))
{
ss<<s3;
ss>>d[j];
ss.clear();
j++;
s3=" ";
}
else
{
s3=s3+s2[n];
}
}
ss<<s3;
ss>>d[j];
ss.clear();
group2.get_(s1,d);
group2.print();
group2.display();
}
}
return 0;
}
题目四:(这题一开始以为是指针的顺序插入,瞎做了半天结果发现是友元函数的调用。。。。)
#include<iostream>
using namespace std;
class Seqlist
{
private:
int date;
public:
void get_(int a)
{
date=a;
}
int out()
{
return date;
}
int print()
{
cout<<date;
}
friend void creat(Seqlist *p);
friend void insert(Seqlist *p,int item);
friend void print(Seqlist *p);
}seqList[12];
int size;
void creat(Seqlist *p)
{
for(int i=0;i<size;i++)
{
int k;
cin>>k;
p[i].get_(k);
}
}
void insert(Seqlist *p,int item)
{
p[size].get_(item);
Seqlist temp;
for(int i=0; i<size; i++)
{
for(int j=0;j<size-i;j++)
{
if(p[j].out()>p[j+1].out())
{
temp=p[j];p[j]=p[j+1];p[j+1]=temp;
}
}
}
size++;
}
void print(Seqlist *p)
{
int i=0;
cout<<"size="<<size<<":";
for(i=0;i<size-1;i++)
{
p[i].print();
cout<<" ";
}
p[i].print();
cout<<endl;
}
int main()
{
int repeat;
cin>>repeat;
for(int i=0;i<repeat;i++)
{
Seqlist p[15];
cin>>size;
creat(p);
int item;
cin>>item;
insert(p,item);
print(p);
}
return 0;
}
第二次收获: