Problem Type : Ad hoc
#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
#include<algorithm>
using namespace std;
struct mymap
{
string p;
int m;
};
mymap arr[2001];
bool comp(mymap n ,mymap x)
{
return(n.p < x.p);
}
int main()
{
int n,i,j,k,y,cou;
string s1;
char s[79],des[76];
scanf("%d",&n);
getchar();
y=0;
for(j=0; j<n; j++)
{
gets(s);
k=0;
for(i=0; i<strlen(s); i++)
{
if((s[i]>='A' && s[i]<='Z')&&!(s[i+1]>=65 && s[i+1]<=90)&&!(s[i+1]>=97 && s[i+1]<=122))
{
des[k]=s[i];
k++;
break;
}
else if ((s[i]>=97 &&s[i]<=122)&&!(s[i+1]>=97 && s[i+1]<=122)&&!(s[i+1]>=65 && s[i+1]<=90))
{
des[k]=s[i];
k++;
break;
}
else if(s[i]>=65 && s[i]<=90 || s[i]>=97 && s[i]<=122)
{
des[k]=s[i];
k++;
}
}
des[k]='\0';
s1=(string)(des);
cou=0;
for(i=0; i<j; i++)
{
if(arr[i].p.compare(s1)==0)
{
cou=1;
arr[i].m++;
}
}
if(cou==0)
{
arr[y].p=s1;
arr[y].m=1;
cou=0;
y++;
}
}
sort(arr,arr+y,comp);
for(i=0; i<y; i++)
{
cout << arr[i].p<<' '<<arr[i].m <<endl;
}
y=0;
for(i=0; i<y; i++)
{
arr[i].m=0;
}
for(i=0; i<y; i++)
{
arr[i].p= '\0';
}
}
#include<iostream>
#include<string>
#include<string.h>
#include<cstdio>
#include<algorithm>
using namespace std;
struct mymap
{
string p;
int m;
};
mymap arr[2001];
bool comp(mymap n ,mymap x)
{
return(n.p < x.p);
}
int main()
{
int n,i,j,k,y,cou;
string s1;
char s[79],des[76];
scanf("%d",&n);
getchar();
y=0;
for(j=0; j<n; j++)
{
gets(s);
k=0;
for(i=0; i<strlen(s); i++)
{
if((s[i]>='A' && s[i]<='Z')&&!(s[i+1]>=65 && s[i+1]<=90)&&!(s[i+1]>=97 && s[i+1]<=122))
{
des[k]=s[i];
k++;
break;
}
else if ((s[i]>=97 &&s[i]<=122)&&!(s[i+1]>=97 && s[i+1]<=122)&&!(s[i+1]>=65 && s[i+1]<=90))
{
des[k]=s[i];
k++;
break;
}
else if(s[i]>=65 && s[i]<=90 || s[i]>=97 && s[i]<=122)
{
des[k]=s[i];
k++;
}
}
des[k]='\0';
s1=(string)(des);
cou=0;
for(i=0; i<j; i++)
{
if(arr[i].p.compare(s1)==0)
{
cou=1;
arr[i].m++;
}
}
if(cou==0)
{
arr[y].p=s1;
arr[y].m=1;
cou=0;
y++;
}
}
sort(arr,arr+y,comp);
for(i=0; i<y; i++)
{
cout << arr[i].p<<' '<<arr[i].m <<endl;
}
y=0;
for(i=0; i<y; i++)
{
arr[i].m=0;
}
for(i=0; i<y; i++)
{
arr[i].p= '\0';
}
}
No comments:
Post a Comment