BestCoder Round #92
Skip the Class
Accepts: 678
Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/65536 K (Java/Others)
#include <iostream> #include <cstdio> #include <vector> #include <queue> #include <cstring> #include <algorithm> #include <cstdlib> #define FOR(i,x,n) for(int i=x;i<n;i++) #define ll long long int #define INF 0x3f3f3f3f #define MOD 1000000007 #define MAX_N 50005 using namespace std; struct node{ char course[20]; int v; }; node no[150]; int compar(char a[],char b[]){ int aa=strcmp(a,b); if(aa>0){ return 1; } return 0; } int compar2(char a[],char b[]){ int aa=strcmp(a,b); if(aa==0){ return 1; } return 0; } int cmp(node a,node b){ return compar(a.course,b.course)||compar2(a.course,b.course)&&a.v>b.v; } int main() { //freopen("data.txt", "r", stdin); //freopen("data.out", "w", stdout); int T; int n; scanf("%d",&T); while(T--){ scanf("%d",&n); FOR(i,0,n){ scanf("%s ",&no[i].course); scanf("%d",&no[i].v); } sort(no,no+n,cmp); int cou; int sum=0; sum+=no[0].v; cou=1; FOR(i,1,n){ if(compar2(no[i].course,no[i-1].course)){ if(cou==1){ sum+=no[i].v; cou++; }else{ continue; } }else{ sum+=no[i].v; cou=1; } } printf("%d ",sum); } //fclose(stdin); //fclose(stdout); return 0; }