• Programmer, Rank Thyself


    虽然没有A过去,但是自己学会了结构体的排序与运用。
    #include
    <iostream> #include <string> #include <algorithm> #include <iomanip> #include <cmath> using namespace std; structTeam { int rank ; stringname; int count ; int time ; int gm ; int Qus[7]; }; Teamt[25]; bool cmp1(Teama1,Teama2) { if(a1.count != a2.count) return a1.count > a2.count; else { if(a1.time != a2.time) return a1.time < a2.time; else { if(a1.gm != a2.gm) return a1.gm < a2.gm; else { for(int i = 0 ; i < a1.name.length() && i < a2.name.length();i++) { if( (int)a1.name[i] - (int)a2.name[1] < 0 ) return true; } return false; } } } } int main() { int n; int total = 0; while(cin>>n && n) { total++; for(int i =0; i < n;i++) { double Log = 1; t[i].count = 0; t[i].gm = 0; t[i].rank = 0; t[i].time = 0; cin>>t[i].name; for(int j =0; j < 7;j++) { cin>>t[i].Qus[j]; t[i].time += t[i].Qus[j]; if(t[i].Qus[j] != 0) { // Log += log(t[i].Qus[j]); t[i].count++; Log *= t[i].Qus[j]; } } if(t[i].count != 0) t[i].gm = (int)(pow(Log,(double)1/t[i].count)+0.5); } sort(t,t+n,cmp1); //得到排名 t[0].rank = 1; int Frank = 1; for(int i = 0; i <n-1;i++) { if(t[i].count == t[i+1].count && t[i].time == t[i].time&&t[i].gm == t[i+1].gm) { t[i+1].rank = t[i].rank; } else { t[i+1].rank = i + 2; } } cout<<"CONTEST "<<total<<endl; for(int i = 0 ; i < n; i++) { if(i < 9) { cout<<"0" <<t[i].rank<<" "<<setw(10)<<left<<t[i].name; // printf("%.2d %-10s%2d%5d%4d", // t[i].rank, t[i].name, // t[i].count, t[i].time, t[i].gm); cout<<" "<<setw(2)<<right<<t[i].count<<setw(5)<<right<<t[i].time<<setw(4) <<right<<t[i].gm; for(int j = 0; j< 7;j++) { cout<<setw(4)<<right<<t[i].Qus[j]; } cout<<endl; } else { cout<<t[i].rank<<" "<<setw(10)<<left<<t[i].name; cout<<" "<<right<<setw(2)<<t[i].count<<right<<setw(5)<<t[i].time<<right<<setw(4) <<right<<t[i].gm; for(int j = 0; j< 7;j++) { cout<<setw(4)<<right<<t[i].Qus[j]; } cout<<endl; } } } return 0; }
  • 相关阅读:
    免费的视频、音频转文本
    Errors are values
    Codebase Refactoring (with help from Go)
    Golang中的坑二
    Cleaner, more elegant, and wrong(msdn blog)
    Cleaner, more elegant, and wrong(翻译)
    Cleaner, more elegant, and harder to recognize(翻译)
    vue控制父子组件渲染顺序
    computed 和 watch 组合使用,监听数据全局数据状态
    webstorm破解方法
  • 原文地址:https://www.cnblogs.com/T8023Y/p/3213670.html
Copyright © 2020-2023  润新知