排序训练的G到J题

G题: HDU - 1236

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define ll long long
#define chushi(a, b) memset(a, b, sizeof(a))
const double eps = 1e-8;
const ll INF = 2e9;
const ll mod = 998244353;
const int maxn = 1e5+5;
using namespace std;

typedef struct Node{			 
	string s;				// 名字 
	int sum;				// 分数 
}node;

int fen[11];
int sum(int n){					// 计算总分, n 为该选手的过题数 
	int tot = 0, num; 
	for(int i = 1; i <= n; i++){
		cin >> num;
		tot += fen[num];
	}
	return tot;
}

int cmp(node a, node b){		// 自定义排序 
	if(a.sum == b.sum) return a.s < b.s;
	return a.sum > b.sum;
}

int main(int argc, char *argv[]) {
	
	ios::sync_with_stdio(false);
	
	int n, m, g;
    while(cin >> n, n != 0){
        cin >> m >> g;
        node v[1005];
        for(int i = 1; i <= m; i++) cin >> fen[i];		// 纪录每个的分数 
        for(int i = 1; i <= n; i++){					
        	cin >> v[i].s;						// 输入名字 
        	int num; cin >> num; 					// 输入过题数 
        	v[i].sum = sum(num);					// 计算总分 
		}
		sort(v+1, v+1+n, cmp);					// 排序 
		int ind = 1;
		while(v[ind].sum >= g && ind <= n) ind++;		// 统计过线的人 
		cout << ind - 1 << endl;
		for(int i = 1; i <= ind - 1; i++) cout << v[i].s << " " << v[i].sum << endl;
    }
	
	return 0;
}

H题: HDU - 2093

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define ll long long
#define chushi(a, b) memset(a, b, sizeof(a))
const double eps = 1e-8;
const ll INF = 2e9;
const ll mod = 998244353;
const int maxn = 1e5 + 5;
using namespace std;

struct node{
    char name[20];				// 人名 
    int cnt;					// 题数 
    int score;					// 分数 
}stu[maxn];

bool cmp(node x,node y){
    if(x.cnt != y.cnt) return x.cnt > y.cnt;
    else if(x.score != y.score) return x.score < y.score;
    else return strcmp(x.name, y.name) < 0;
}

int main(){
	
	int n,m;
    while(~scanf("%d%d", &n, &m)){
        int t = 0;										// 统计人数 
        char ch[10];								 
        while(scanf("%s", stu[t].name) != EOF){

            stu[t].cnt = 0, stu[t].score=0;
            for(int i = 0; i < n; i++){
                scanf("%s", ch);
                if(ch[0] == '-') continue;
                if(strcmp(ch, "0") == 0) continue;   
                stu[t].cnt++;   				// 更新题数
                int j, tmp = 0;
                for(j = 0; j < strlen(ch); j++){		// 计算答题时间 
                    if(ch[j]=='(') break;
                    tmp = tmp * 10 + ch[j] - '0';
                }
                stu[t].score += tmp;				// 更新结果 
                tmp = 0;
                if(j < strlen(ch)){      			//判断是否出错 
                    for(int k = j + 1; k < strlen(ch)-1; k++){
                        tmp = tmp * 10 + ch[k] - '0';
                    }
                }
                stu[t].score += tmp * m;			// 再次更新结果 
            }
            t++;						// 更新人数 
        }
        sort(stu, stu+t, cmp);                    
		for(int i = 0; i < t; i++){                  
			printf("%-10s%3d%5d\n",stu[i].name, stu[i].cnt, stu[i].score);
        }
    }

    return 0;

}

I题: HDU - 1040

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define ll long long
#define chushi(a, b) memset(a, b, sizeof(a))
const double eps = 1e-8;
const ll INF = 2e9;
const ll mod = 998244353;
const int maxn = 1e5+5;
using namespace std;

int main(int argc, char *argv[]) {
	
	ios::sync_with_stdio(false);
	
	int ncase;
    cin >> ncase;
    
    while(ncase--){
        int n;
        cin >> n;
        long long a[n];
        for(int i = 0; i < n; i++) cin >> a[i];
        sort(a, a +n);
        cout << a[0];
        for(int i = 1; i < n; i++) cout << " " << a[i];
        cout << endl;
    }
	
	return 0;
}

J题: HDU - 1106

#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define ll long long
#define chushi(a, b) memset(a, b, sizeof(a))
const double eps = 1e-8;
const ll INF = 2e9;
const ll mod = 998244353;
const int maxn = 1e5+5;
using namespace std;

int main(int argc, char *argv[]) {
	
	ios::sync_with_stdio(false);
	
	string s;
	
	while(cin >> s){
		replace(s.begin(),s.end(),'5',' ');   	    // 把所有的 5 变成 空格,不变也可以,后边以 5 为结尾标志就可以 
		vector<int>v;				 // 纪录转化出来的数字   
		s = " " + s;				 //   空格 + 数字 + 空格 + .... 
		int ind = 0;
		while(ind < s.size()){
			if(s[ind] == ' ') ind++;		// 空格就跳过 
			else{
				string num = "";					
				while(s[ind] != ' ' && ind < s.size()){		// 分离字符串
					num += s[ind];
					ind++;
				}
				int a = atoi(num.c_str());	// 字符串转数字 
				v.push_back(a);
			}
		}
		sort(v.begin(), v.end());			// 排序 
		cout << v[0];
		for(int i = 1; i < v.size(); i++) cout << " " << v[i];
		cout << endl;
	}
	
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值