- 问答
- 2014-01-25 13:22:54 @
#include <iostream>
#include <string.h>
#include <ctype.h>
using namespace std;
struct student
{
char name[30]; int score; int sclass; int iscad; int iswest ; int publish;
int sholarship;
void ReadC()
{
iswest = 0;
iscad = 0;
sholarship = 0;
char tmp;
cin>>this->name>>this->score>>this->sclass;
cin>>tmp;
tmp = toupper(tmp);
if(tmp == 'Y')
this->iscad = 1;
cin>>tmp;
tmp = toupper(tmp);
if(tmp == 'Y')
this->iswest = 1;
cin>>this->publish;
if(score>80&&publish>=1)
sholarship+=8000;
if(score>85&&sclass>80)
sholarship+=4000;
if(score>90)
sholarship+=2000;
if(score>85&&iswest)
sholarship+=1000;
if(score>80&&iscad)
sholarship+=850;
}
};
int main()
{
student stu[100]; student* p_n;
int maxt=0,maxn=0,all=0;
int n;
while(cin>>n)
{
maxt=0,maxn=0,all=0;
p_n = NULL ;
memset(stu,0x00,sizeof(stu));
for(int i=0;i<n;i++)
{
p_n = &stu[i];
p_n->ReadC();
all+=p_n->sholarship;
if(p_n->sholarship>maxt)
{
maxt =p_n->sholarship;
maxn = i;
}
}
p_n=&stu[maxn];
cout<<p_n->name<<endl<<p_n->sholarship<<endl<<all<<endl;
}
return 0;
}
评测结果
编译成功
测试数据 #0: Accepted, time = 0 ms, mem = 268 KiB, score = 10
测试数据 #1: WrongAnswer, time = 15 ms, mem = 272 KiB, score = 0
测试数据 #2: WrongAnswer, time = 0 ms, mem = 268 KiB, score = 0
测试数据 #3: WrongAnswer, time = 15 ms, mem = 268 KiB, score = 0
测试数据 #4: Accepted, time = 15 ms, mem = 268 KiB, score = 10
测试数据 #5: WrongAnswer, time = 0 ms, mem = 268 KiB, score = 0
测试数据 #6: WrongAnswer, time = 15 ms, mem = 272 KiB, score = 0
测试数据 #7: Accepted, time = 15 ms, mem = 268 KiB, score = 10
测试数据 #8: WrongAnswer, time = 15 ms, mem = 268 KiB, score = 0
测试数据 #9: WrongAnswer, time = 0 ms, mem = 272 KiB, score = 0
WrongAnswer, time = 90 ms, mem = 272 KiB, score = 30
想不通,总是只有三个测评点通过
2 条评论
-
fcoaxt LV 8 @ 2014-12-14 17:41:51
大哥写这么多干嘛。。
#include<stdio.h>
#include<algorithm>
using namespace std;
struct score
{
int num;
int yw;
int sx;
int yy;
int total;
}stu[320];
int cmp(score x,score y)
{
if(x.total>y.total)
return 1;
if(x.total==y.total&&x.yw>y.yw)
return 1;
if(x.total==y.total&&x.yw==y.yw&&x.num<y.num)
return 1;
return 0;
}
int main()
{
int a,b,c,d;
scanf("%d",&a);
for(b=1;b<=a;b++)
{
stu[b].num=b;
scanf("%d %d %d",&stu[b].yw,&stu[b].sx,&stu[b].yy);
stu[b].total=stu[b].yw+stu[b].sx+stu[b].yy;
}
sort(stu+1,stu+1+a,cmp);
for(d=1;d<=a;d++)
if(stu[d].total==stu[d+1].total);
for(c=1;c<=5;c++)
printf("%d %d\n",stu[c].num,stu[c].total);
return 0;
}虽然不让用sort手一滑。。
-
2014-01-26 21:57:03@
类用的有些乱了,我觉得要用类和流的话这样写比较好
#include <iostream>
#include <vector>
#include <algorithm>using namespace std;
class student
{
friend istream& operator >>
(ostream&, student&);
public:
student():name(""), total(0), index(0){}
string name;int total;
int index;
};
inline bool operator <
(const student& a, const student &b)
{
if(a.total == b.total) return a.index < b.index;
return a.total > b.total;
}
istream&
operator >>(istream& in, student& s)
{
string W, O;
int ave, disscuss, words;
in >> s.name
>> ave >> disscuss
>> O >> W
>> words;if(words > 0 && ave > 80){
s.total += 8000;
}
if(ave > 85 && disscuss > 80){
s.total += 4000;
}
if(ave > 90){
s.total += 2000;
}
if(W == "Y" && ave > 85){
s.total += 1000;
}
if(O == "Y" && disscuss > 80){
s.total += 850;
}return in;
}vector<student> data;
void read();
void out();int main()
{
read();
sort(data.begin(), data.end());
out();
return 0;
}void read()
{
int N;cin >> N;
for(int i = 0; i < N; ++i){
student t;
cin >> t;
t.index = i + 1;
data.push_back(t);
}
}void out()
{
int ans = 0;
for(vector<student>::iterator i = data.begin(); i != data.end(); ++i) ans += i->total;
cout << data.begin()->name << endl
<< data.begin()->total << endl
<< ans;}
- 1