| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
487-3279#include<iostream>
#include<string>
using namespace std;
#define LEN sizeof(struct node)
string get() {
string str1=" ";
string str2;
cin>>str2;
//cout<<str2<<endl;
int i=0;
int j=1;
while(str2[i] != '\0') {
switch(str2[i]) {
case 'A':
case'B':
case 'C':
case'2':str1[j++] = '2';
break;
case 'D':
case 'E':
case 'F':
case '3':str1[j++] = '3';
break;
case 'G':
case 'H':
case 'I':
case '4':str1[j++] = '4';
break;
case 'J':
case 'K':
case 'L':
case '5':str1[j++] = '5';
break;
case 'M':
case 'N':
case 'O':
case '6':str1[j++] = '6';
break;
case 'P':
case 'R':
case 'S':
case '7':str1[j++] = '7';
break;
case 'T':
case 'U':
case 'V':
case '8':str1[j++] = '8';
break;
case 'W':
case 'X':
case 'Y':
case '9':str1[j++] = '9';
break;
}
i++;
}
for(j = 0;j<3;j++)
{
str1[j] = str1[j+1];
}
str1[3] = '-';
return str1;
}
struct node {
string str ;
int count;
node *next;
};
node *list[7]={NULL};
int main() {
int n = 0;
node *p = NULL;
node *q =NULL;
string str =" " ;
cin>>n;
for(int i=0;i<n;i++) {
str = get();
q = new node;
q->str = str;
q->count = 1;
q->next = NULL;
if(list[str[0]-2-48] == NULL) {
list[str[0]-2-48] = q;
//cout<<(*list[0]).str<<(*list[0]).count<<endl;
}
else{
p = list[str[0]-2-48];
while ((*p).next !=NULL) {
if((*p).str != str)
p = (*p).next;
else{
(*p).count++;
p = NULL;
break;
}
}
if(p)
if((*p).str != str){
(*p).next = q;
}
else{
(*p).count++;
}
}
}
for(int k=0;k<8;k++) {
if(list[k] != NULL){
p = list[k];
while(p)
{
if((*p).count >1)
{
cout<<(*p).str<<' '<<(*p).count<<endl;
}
p = (*p).next;
}
}
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator