Hdu 1084 What Is Your Grade?解题报告
2008-05-10 17:36
405 查看
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<iostream>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<vector>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<string>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
#include<algorithm>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
using namespace std;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
struct Grade
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int nums;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int grade;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
string times;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
vector <Grade> g;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int cnt[6];
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int n;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
bool cmp1(Grade a, Grade b)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (a.nums==b.nums)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return a.times<b.times;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return a.nums>b.nums;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
bool cmp2(Grade a, Grade b)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return a.index<b.index;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
void getGrade()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
int cnt2[6]=...{0};
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(int i=0;i<n;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (g[i].nums==5)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g[i].grade=100;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else if (g[i].nums==0)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g[i].grade=50;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int k=g[i].nums;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (cnt2[k]<cnt[k])
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g[i].grade=55+k*10;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cnt2[k]++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g[i].grade=50+k*10;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
bool run()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cin >> n;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (n<0) return false;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g.resize(n);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(i=0;i<6;i++) cnt[i]=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(i=0;i<n;i++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cin>>g[i].nums >>g[i].times;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
g[i].index=i;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cnt[g[i].nums]++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sort(g.begin(),g.end(),cmp1);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(i=0;i<6;i++) cnt[i]/=2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
getGrade();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sort(g.begin(),g.end(),cmp2);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
for(i=0;i<n;i++) cout << g[i].grade << endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
cout<<endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
int main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
while(run());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return 0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
排序的一般方法,还要一点细心。方便起见,用用全局的数组,变量等。
相关文章推荐
- HDU 1084(What Is Your Grade?)解题纠错
- hdu 1084 What Is Your Grade?
- HDU 1084 What Is Your Grade?(排序)
- HDU——1084 What is your grade?(莫名的Wrong Answer)
- HDU 1084 What Is Your Grade?
- HDU ACM 1084 What Is Your Grade?
- HDU 问题1084 What Is Your Grade?(结构体+sort)
- hdu 1084 What Is Your Grade?
- HDU 1084 What Is Your Grade?
- hdu 1084 What Is Your Grade?
- HDU 1084 What Is Your Grade?
- HDOJ HDU 1084 What Is Your Grade?
- HDU-1084-What Is Your Grade?
- HDU 1084 What Is Your Grade?
- HDU 1084 - What Is Your Grade?
- HDU 1084 What Is Your Grade?
- HDU 1084 What Is Your Grade? (模拟题)
- HDU 1084 What Is Your Grade?
- hdu 1084 What Is Your Grade?
- HDU 1084 What Is Your Grade