沃老师学生的成绩+stl string 的删除操作,加map的自动排序

题目链接

思路:stl大法好 将字符的末尾0给去掉,然后比较string的大小,同时用map的自动排序将名字按照字典序输出,>>>stl大法好

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
using namespace std;
const int N=2e5+10;
map<string,int>a;
map<string,string>b;
struct node{string a,b;}d[N];
void solve(string &s1){
    int len1=s1.size();
    auto it=s1.end();it--;
    while(it!=s1.begin()&&*it==‘0‘) s1.erase(it),it--;
}
typedef pair<string,string>P;vector<P>vv;
bool cmp(P s1,P s2){return s1.second>s2.second||(s1.second==s2.second&&s1.first<s2.first);}
int main(){
    std::ios::sync_with_stdio(false);cin.tie(0);
    int n;
    while(cin>>n){
        string s1,s2;
        while(!vv.empty()) vv.pop_back();
        a.clear(),b.clear();
        for(int i=1;i<=n;i++){
            cin>>s1>>s2;
            d[i].a=s1,d[i].b=s2;
            solve(s2);vv.push_back({s1,s2}),a[s1]=i;
        }
        int tot=1;
        sort(vv.begin(),vv.end(),cmp);
        for(auto it=vv.begin();it!=vv.end();it++){
            string tmp=it->first;
            cout<<tmp<<" "<<d[a[tmp]].b<<endl;
        }
    }
    return 0;
}

原文地址:https://www.cnblogs.com/vainglory/p/8933457.html

时间: 2024-08-09 18:41:25

沃老师学生的成绩+stl string 的删除操作,加map的自动排序的相关文章

STL - string(典型操作demo)

1String概念 string是STL的字符串类型,通常用来表示字符串.而在使用string之前,字符串通常是用char*表示的.string与char*都可以用来表示字符串,那么二者有什么区别呢. string和char*的比较 string是一个类, char*是一个指向字符的指针. string封装了char*,管理这个字符串,是一个char*型的容器. string不用考虑内存释放和越界. string管理char*所分配的内存.每一次string的复制,取值都由string类负责维护

初学Java3:数组-从键盘录入若干学生的成绩,计算平均值,最大值,最小值

//任务:从键盘录入若干学生的成绩,计算平均值,最大值,最小值package com.azhi;//纠正昨天的包名,今天老师说要以反域名命名,昨天还不知道,今天就这么弄了一个import java.util.Scanner;public class Text_Array { public static void main(String[] args){ Scanner sc=new Scanner(System.in);//从键盘输入 System.out.print("请输入学生个数:&quo

用链表写的学生管理系统 成绩的录入与查询都已经是实现了

#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct teacher { char name[32]; int math; int english; int data; struct Node *next; }SLIST; int Creat_SList(); int SList_Print(); int SLis

从键盘输入5个学生的成绩,并求出最高分 Max1.java

//从键盘输入5个学生的成绩,并求出最高分import java.util.Scanner;public class Max1 { public static void main(String[] args){ Scanner in=new Scanner(System.in); int[] arr=new int[5]; for(int i=0;i<arr.length;i++){ System.out.println("请输入第"+(i+1)+"个学生的成绩&quo

HashSet ——学生姓名&amp;成绩

Implement HashSet to store ‘n’ records of students ( Name, Percentage). Write a menu driven program to : 1. Add student 2. Display details of all students 3. Search student 4. Find out highest marks 1 package Aug11.Collection; 2 3 import java.util.*;

题目1069:查找学生信息(STL的map简单应用)

题目描述: 输入N个学生的信息,然后进行查询. 输入:                        输入的第一行为N,即学生的个数(N<=1000) 接下来的N行包括N个学生的信息,信息格式如下: 01 李江 男 21 02 刘唐 男 23 03 张军 男 19 04 王娜 女 19 然后输入一个M(M<=10000),接下来会有M行,代表M次查询,每行输入一个学号,格式如下: 02 03 01 04 输出:                        输出M行,每行包括一个对应于查询的学

java编写一个可以进行多个选择题测验评分的程序(从高分到低分依次输出学生和成绩)

public class GradeExam { public static void main(String[] args) { char[][] answers = { {'A','B','A','C','C','D','E','E','A','D'}, {'D','B','A','B','C','A','E','E','A','D'}, {'E','D','D','A','C','B','E','E','A','D'}, {'C','B','A','E','D','C','E','E','

Java笔试题-C盘下面有一个aa.txt的文件,文件里存放了年级每一个学生的成绩看,格式为:姓名 分数 班级

题目:C盘下面有一个aa.txt的文件,文件里存放了年级每一个学生的成绩看,格式为:姓名 分数 班级如: 张三80 1班 李四90 2班 设计一个方法,读取文件里的信息,最后输出学生的信息,输出格式为:姓名:张三 分数:80 班级:1班 要求:使用类存储每一行学生信息,使用list存储所有的学生信息. public class ReadTextLine { public static void main(String[] args) throws IOException { List<Stude

键盘录入学生的成绩,将100分划分四个等级,优.良.及.不及。输出对应的等级,要有容错处理

1 import java.util.InputMismatchException; 2 import java.util.Scanner; 3 4 /* 5 键盘录入学生的成绩,将100分划分四个等级,优.良.及.不及.输出对应的等级,要有容错处理 6 */ 7 public class Demo { 8 public static void main(String[] args){ 9 Scanner sc = new Scanner(System.in); 10 try { 11 whil