(Cutting string) result inquiry system

Y math teacher to write a small achievement inquiry system, contains the following command:
INSERT [name] [Score], insert a message into the system, as the name represents the name of student math scores for the score.
find [name], it means the search for the name of the name of the student in math.
Note that some students may be repeated for elective Shuafen, query time to give the maximum performance.
Student's name is lowercase letters. Score is an integer from 0 ... 100.

Sample input:

90 zhangsan INSERT
INSERT Lisi 78
INSERT Xiaoming 86
Find Xiaoming
Find Jack
End

Sample output:

86

-1

#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <string.h> 
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;

int n,m;
int ans=0;
bool vis[105];
int dp[105],aa[105];
map<string,int> mp;
int main() {
    string op,name,sc;
    while(getline(cin,op)){
        stringstream ss(op);
        if(ss>>op){
            if(op=="end"){
                return 0;
            }
            else if(op=="insert"){
                ss>>op;                         //字符后移 
                name=op;
                ss>>op;
                sc=op;
                int sum=0;
                for(int i=0;i<sc.length();i++){
                    sum=sum*10+(sc[i]-'0');
                }
                if(mp[name]<sum){
                    mp[name]=sum;
                }
            }
            else{
                ss>>op;
                name=op;
                if(mp.count(name))
                cout<<mp[name]<<endl;
                else
                cout<<-1<<endl;
            }
        }
    } 
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/xusi/p/12614203.html