POJ3297+map字符串处理

时间:2022-01-29 15:28:20

简单的字符串处理题。

要注意细节!

附数据两组:

ABCC
abc
ae
AAA
abc
AAAA
abc A
a
B
a
C
a
 /*

 */
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int maxm = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-; struct Node{
string name;
int cnt;
}project[ maxn ];
map<string,int>mp;
map<string,int>special;
void init(){
mp.clear();
special.clear();
}
int cmp( Node a,Node b ){
if( a.cnt!=b.cnt )
return a.cnt>b.cnt;
else
return a.name<b.name;
}
int main(){
string temp;
while( getline( cin,temp ) ){
//cout<<"temp = "<<temp<<endl;
if( ''==temp[] )
break;
if( ''==temp[] )
continue;
init();
int Num = ;
while( ){
project[ Num ].name = temp;
project[ Num ].cnt = ;
while( ){
getline( cin,temp );
//cout<<"temp = "<<temp<<endl;
if( temp.size()==&&temp[]=='' ) break;
if( ( temp[]>='a'&&temp[]<='z' )||( temp[]>=''&&temp[]<='' ) ){
if( mp[ temp ]== ){
mp[ temp ] = Num;
project[ Num ].cnt ++ ;
}
else {
if( mp[ temp ]==Num ){}
else if( special[ temp ]== ){
special[ temp ] = ;
if( project[ mp[temp] ].cnt> )
project[ mp[ temp ] ].cnt --;
}
}
}
else
break;
}
Num ++ ;
if( ''==temp[] ) break;
}
//cout<<"ok"<<endl;
sort( project+,project+Num,cmp );
for( int i=;i<Num;i++ ){
cout<<project[i].name<<" "<<project[i].cnt<<endl;
}
}
return ;
}