错误原因
1.第三个测试点过不过去的原因,因为会出现期中成绩为0分,期末成绩为-1分
这个时候最后的总成绩是0分
2.但是如果初始值 int Gp=0,Gm=0,Gf=0,G=0;
G总成绩一开始是0的话,那么我们判断条件是这样的(mp[it].G!=0?mp[it].G:-1)
它混淆了期中和期末都没有成绩
和
期中0分,期末没有成绩的情况
这个判断条件下它输出都是-1;但是前一种情况是-1,但是后面的一种情况输出应该是0
19分代码
#include <bits/stdc++.h>
//#define int long long
#define eb emplace_back
#define pii pair<int,int>
#define endl "\n"
using namespace std;
using ll=long long;
const ll mod=1e9+7;
const int N=50+10;
int p,n,m;
string stuid;
int score;
struct node
{
string stuid;
// int Gp=0,Gm=-1,Gf=-1,G=0;
int Gp=0,Gm=0,Gf=0,G=0;
};
unordered_map<string,node>mp;
auto check()
{
vector<string>tmp;
for(auto &it:mp)
{
auto curnode=it.second;
double grade;
if( curnode.Gm>curnode.Gf)grade=((curnode.Gm)*0.4+(curnode.Gf)*0.6)+0.5;
else grade=curnode.Gf;
if(grade>=60 )
{
// cout<<grade<<"==\n";
it.second.G=int(grade);
tmp.eb(it.first);
// cout<<it.second.G<<"**\n";
}
}
return tmp;
}
bool cmp(string str1,string str2)
{
if(mp[str1].G!=mp[str2].G)return mp[str1].G>mp[str2].G;
else return mp[str1].stuid<mp[str2].stuid;
}
void solve()
{
cin>>p>>n>>m;
for(int i=0;i<p;++i)
{
cin>>stuid>>score;
if(score<200)continue;
node student;
student.stuid=stuid,student.Gp=score;
mp[stuid]=student;
}
for(int i=0;i<n;++i)
{
cin>>stuid>>score;
if(mp.count(stuid))mp[stuid].Gm=score;
}
for(int i=0;i<m;++i)
{
cin>>stuid>>score;
if(mp.count(stuid))mp[stuid].Gf=score;
}
auto vec=check();//寻找当前满足条件的学生;
sort(vec.begin(),vec.end(),cmp);
for(auto it:vec)
{
// cout<<it<<"\n";
cout<<mp[it].stuid<<" "<<mp[it].Gp<<" "<<(mp[it].Gm!=0?mp[it].Gm:-1)<<" "<<(mp[it].Gf!=0?mp[it].Gf:-1)<<" "<<(mp[it].G!=0?mp[it].G:-1)<<"\n";
// cout<<mp[it].stuid<<" "<<mp[it].Gp<<" "<<mp[it].Gm<<" "<<mp[it].Gf<<" "<<mp[it].G<<"\n";
}
}
int main()
//signed main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T=1;
while(T--)
{
solve();
}
return 0;
}
/*
1.第三个测试点过不过去的原因,因为会出现期中成绩为0分,期末成绩为-1分
这个时候最后的总成绩是0分
2.但是如果初始值 int Gp=0,Gm=0,Gf=0,G=0;
G总成绩一开始是0的话,那么我们判断条件是这样的(mp[it].G!=0?mp[it].G:-1)
它混淆了期中和期末都没有成绩
和
期中0分,期末没有成绩的情况
这个判断条件下它输出都是-1;但是前一种情况是-1,但是后面的一种情况输出应该是0
*/
AC代码
#include <bits/stdc++.h>
//#define int long long
#define eb emplace_back
#define pii pair<int,int>
#define endl "\n"
using namespace std;
using ll=long long;
const ll mod=1e9+7;
const int N=50+10;
int p,n,m;
string stuid;
int score;
struct node
{
string stuid;
int Gp=0,Gm=-1,Gf=-1,G=0;
// int Gp=0,Gm=0,Gf=0,G=0;
};
unordered_map<string,node>mp;
auto check()
{
vector<string>tmp;
for(auto &it:mp)
{
auto curnode=it.second;
double grade;
if( curnode.Gm>curnode.Gf)grade=((curnode.Gm)*0.4+(curnode.Gf)*0.6)+0.5;
else grade=curnode.Gf;
if(grade>=60 )
{
// cout<<grade<<"==\n";
it.second.G=int(grade);
tmp.eb(it.first);
// cout<<it.second.G<<"**\n";
}
}
return tmp;
}
bool cmp(string str1,string str2)
{
if(mp[str1].G!=mp[str2].G)return mp[str1].G>mp[str2].G;
else return mp[str1].stuid<mp[str2].stuid;
}
void solve()
{
cin>>p>>n>>m;
for(int i=0;i<p;++i)
{
cin>>stuid>>score;
if(score<200)continue;
node student;
student.stuid=stuid,student.Gp=score;
mp[stuid]=student;
}
for(int i=0;i<n;++i)
{
cin>>stuid>>score;
if(mp.count(stuid))mp[stuid].Gm=score;
}
for(int i=0;i<m;++i)
{
cin>>stuid>>score;
if(mp.count(stuid))mp[stuid].Gf=score;
}
auto vec=check();//寻找当前满足条件的学生;
sort(vec.begin(),vec.end(),cmp);
for(auto it:vec)
{
// cout<<it<<"\n";
// cout<<mp[it].stuid<<" "<<mp[it].Gp<<" "<<(mp[it].Gm!=0?mp[it].Gm:-1)<<" "<<(mp[it].Gf!=0?mp[it].Gf:-1)<<" "<<(mp[it].G!=0?mp[it].G:-1)<<"\n";
cout<<mp[it].stuid<<" "<<mp[it].Gp<<" "<<mp[it].Gm<<" "<<mp[it].Gf<<" "<<mp[it].G<<"\n";
}
}
int main()
//signed main()
{
// ios::sync_with_stdio(0);
// cin.tie(0);
// cout.tie(0);
int T=1;
while(T--)
{
solve();
}
return 0;
}
/*
1.第三个测试点过不过去的原因,因为会出现期中成绩为0分,期末成绩为-1分
这个时候最后的总成绩是0分
2.但是如果初始值 int Gp=0,Gm=0,Gf=0,G=0;
G总成绩一开始是0的话,那么我们判断条件是这样的(mp[it].G!=0?mp[it].G:-1)
它混淆了期中和期末都没有成绩
和
期中0分,期末没有成绩的情况
这个判断条件下它输出都是-1;但是前一种情况是-1,但是后面的一种情况输出应该是0
*/