【每日】1164考试排名——中级

如图
一道输入,判断,排序,输出题。

学到的点:

  1. 结构体vector的push_back 和sort
  2. log要用换底公式
  3. 编译的时候直接按特定if里的当前行可以跳过其它组数据
  4. 输出时的iomanip 头文件
I/O流常用控制符:

使用控制符时,在程序开头加投文件#include <iomanip> C++有两种方法控制格式输出:1、用格式控制符;2、用流对象的成员函数 格式控制符:

dec                                 设置基数为10

hex                                 设置基数为16

oct                                 设置基数为8

setfill(c)                          设置填充字符c

setprecision(n)                     设置显示小数精度为nsetw(n)                             设置域宽为n个字符

setiosflags(ios::fixed)             固定的浮点显示

 setiosflags(ios::scientific)        指数表示

setiosflags(ios::left)              左对齐

setiosflags(ios::right)             右对齐

setiosflags(ios::skipws)            忽略前导空白

setiosflags(ios::uppercase)         16进制数大写输出

setiosflags(ios::lowercase)         16进制小写输出

代码如下

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
#include<iomanip>
#include<vector>
#include<sstream>
#include<algorithm>
#include<cmath>
using namespace std;
struct acm {
    string name;
    int score;
    int time;
};

bool cmp(acm x, acm y) {
    if (x.score != y.score)return x.score > y.score;
    else return x.time < y.time;
}
int main()
{
    vector<acm> a;
    //acm first;
    float m, n;
    cin >> m >> n;
    //a.push_back(first);
    int t = 0;
    string s;
    while (cin >> s) {
        acm now;
        now.name = s;
        now.time = 0;
        now.score = 0;
        for (int i = 0; i < m; i++) {
            string x;
            cin >> x;
                stringstream ss(x);
            int y;
            string z;
            ss >> y;
            ss >> z;

            //if (y < 0) now.time += -y;
            //if (y == 0);
            if (y > 0) {
                now.score += 1;
                now.time += y;
                int q = (int)(log(y)/log(10)) + 1,w= x.length();
                if (x.length() > q) 
                {z = x.substr(q+1, x.length() - 2);

                    stringstream sss(z);
                int yy;
                sss >> yy;
                now.time += yy*n;
                }
            }
        }
        a.push_back(now);

    }
    sort(a.begin(), a.end(), cmp);
    for (int j = 0; j < a.size(); j++) {
        //cout << a[j].name << endl;
        cout << setw(10) << setiosflags(ios::left) << a[j].name;
        cout << setw(2) << a[j].score;
        printf("%4d\n", a[j].time);
    }



    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值