1085. PAT单位排行 (25)

1085. PAT单位排行 (25)
1141. PAT Ranking of Institutions (25)

#include <bits/stdc++.h>
using namespace std;
struct node
{
    int rank;
    string school;
    int tws,ns;
    node(int r,string s,int t,int n):rank(r),school(s),tws(t),ns(n){}
};
map<string,pair<int,double>> mp;
double cptscore(char x,double score)
{
    if(x=='B') score/=1.5;
    if(x=='T') score*=1.5;
    return score;
}
void lr(char school[],int len)
{
    for(int i=0;i<len;++i){
        if(isupper(school[i])){
            school[i]=tolower(school[i]);
        }
    }
}
bool cmp(const node &a,const node &b)
{
    if(a.tws!=b.tws)
        return a.tws>b.tws;
    return a.ns==b.ns?a.school<b.school:a.ns<b.ns;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        char id[12],school[12];
        double score;
        scanf("%s %lf %s",id,&score,school);
        score=cptscore(id[0],score);
        lr(school,strlen(school));
        auto &res=mp[school];
        res.first++;
        res.second+=score;
    }
    vector<node> v;
    for(auto &x:mp){
        string school=x.first;
        int ns=x.second.first,tws=x.second.second;
        v.push_back(node(0,school,tws,ns));
    }
    sort(v.begin(),v.end(),cmp);
    int l=v.size();
    v[0].rank=1;
    for(int i=1;i<l;++i){
        v[i].rank=(v[i].tws==v[i-1].tws)?v[i-1].rank:i+1;
    }
    printf("%d\n",l);
    for(node &x:v){
        printf("%d %s %d %d\n",x.rank,x.school.c_str(),x.tws,x.ns);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您想读取.pat文件并添加内容,可以按照以下步骤操作: 1. 使用C++的fstream库打开.pat文件,例如: ```cpp #include <fstream> #include <iostream> int main() { std::ifstream file("example.pat"); if (file.is_open()) { // 文件成功打开,可以进行读取和写入操作 std::cout << "File opened successfully!\n"; } else { // 文件打开失败,输出错误信息 std::cerr << "Failed to open file!\n"; } return 0; } ``` 2. 读取文件内容并添加新内容,例如: ```cpp #include <fstream> #include <iostream> int main() { std::ifstream file("example.pat"); if (file.is_open()) { // 文件成功打开,可以进行读取和写入操作 std::cout << "File opened successfully!\n"; // 读取文件内容 std::string line; while (std::getline(file, line)) { std::cout << line << '\n'; } // 添加新内容 std::ofstream outfile("example.pat", std::ios::app); if (outfile.is_open()) { outfile << "New content\n"; std::cout << "New content added successfully!\n"; } else { std::cerr << "Failed to add new content!\n"; } } else { // 文件打开失败,输出错误信息 std::cerr << "Failed to open file!\n"; } return 0; } ``` 3. 关闭文件,例如: ```cpp #include <fstream> #include <iostream> int main() { std::ifstream file("example.pat"); if (file.is_open()) { // 文件成功打开,可以进行读取和写入操作 std::cout << "File opened successfully!\n"; // 读取文件内容 std::string line; while (std::getline(file, line)) { std::cout << line << '\n'; } // 添加新内容 std::ofstream outfile("example.pat", std::ios::app); if (outfile.is_open()) { outfile << "New content\n"; std::cout << "New content added successfully!\n"; } else { std::cerr << "Failed to add new content!\n"; } // 关闭文件 file.close(); outfile.close(); } else { // 文件打开失败,输出错误信息 std::cerr << "Failed to open file!\n"; } return 0; } ``` 这样您就可以读取.pat文件并添加新内容了。请注意,在添加新内容时,我们使用了std::ofstream库和std::ios::app参数来打开文件以追加内容。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值