while True: try: num=int(input()) m=int(input()) table=[] for each in range(num): tableLine=input().split(' ') name,score=tableLine[0],int(tableLine[1]) table.append((name,score)) if m==0: newTable=sorted(table,key=lambda x:x[1],reverse=True) else: newTable=sorted(table,key=lambda x:x[1]) for each in newTable: print(each[0]+' '+str(each[1])) except: break
#include <iostream> #include <string> #include <vector> using namespace std; int main(){ int num,n,score; string name; while(cin >> num >> n){ vector<string> b[101]; for(int i=0;i<num;i++){ cin >> name >> score; b[score].push_back(name); } if(n==0){ for(int i=100;i>=0;i--){ for(int j=0;j<b[i].size();j++) cout << b[i][j] << " " << i << endl; } } else{ for(int i=0;i<101;i++){ for(int j=0;j<b[i].size();j++) cout << b[i][j] << " " << i << endl; } } } return 0; }