#include <iostream>
#include <set>
#include <string>
using namespace std;
int main()
{
string str;
set<string> se;
char c;
int n;
while(1)
{
cin>>str;
se.insert(str);
c=getchar();
if(c=='\n')
break;
}
n=0;
for(set<string>::iterator it=se.begin();it!=se.end();it++)
{
str=*(it);
if(n==0)
{
c=str[0];
n++;
}
else if(str[0]==c)
{
n++;
}
else
{
cout<<c<<" "<<n<<endl;
n=1;
c=str[0];
}
}
cout<<c<<" "<<n<<endl;
n=1;
c=str[0];
return 0;
}
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
#include <map>
using namespace std;
int main()
{
string str;
set<string> s;
map<char,int> ma;
while(cin>>str)
{
s.insert(str);
}
for(set<string>::iterator it=s.begin();it!=s.end();it++)
{
ma[(*it)[0]]++;
}
for(map<char ,int>::iterator m=ma.begin();m!=ma.end();m++)
{
cout<<m->first<<m->second<<endl;
}
}
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(string a,string b)
{
return a<b;
}
int main()
{
char c;
string str;
vector<string> vi;
while(1)
{
cin>>str;
vi.push_back(str);
c=getchar();
if(c=='\n')
break;
}
sort(vi.begin(),vi.end(),cmp);
for(vector<string>::iterator it=vi.begin();it!=vi.end();it++)
{
cout<<(*it)<<" ";
}
cout<<endl;
return 0;
}
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
vector<string> vi;
string str;
while(cin>>str)
{
vi.push_back(str);
}
sort(vi.begin(),vi.end());
for(vector<string>::iterator it=vi.begin();it!=vi.end();it++)
{
cout<<(*it)<<" ";
}
cout<<endl;
}
(aaaa(bbbb(cccc,dddd),eeee(ffff)))
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#define MaxSize 100
using namespace std;
typedef struct
{
char name[20];
int leader; //leader's num
}worker;
int main()
{
int n=0,leader=-1;
char ch[100],last='\0';
worker w[MaxSize];
stack<worker> s;
gets(ch);
int i=0,j=0;
while(ch[i]!='\0')
{
if(ch[i]=='(')
{
if(last>='a' && last<='z' || last>='A' && last<='Z' )
{
w[n].name[j]='\0';
w[n].leader=leader;
n++;
j=0;
}
leader=n-1;
}
else if(ch[i]==')')
{
if(last>='a' && last<='z' || last>='A' && last<='Z' )
{
w[n].name[j]='\0';
w[n].leader=leader;
n++;
j=0;
}
leader=w[leader].leader;
}
else if(ch[i]==',')
{
if(last>='a' && last<='z' || last>='A' && last<='Z' )
{
w[n].name[j]='\0';
w[n].leader=leader;
n++;
j=0;
}
}
else if(ch[i]>='a' && ch[i]<='z' || ch[i]>='A' && ch[i]<='Z')
{
w[n].name[j++]=ch[i];
}
last=ch[i++];
}
cout<<"请输入一个姓名"<<endl;
char a[20];
cin>>a;
for(i=0;i<n;i++)
{
if(strcmp(a,w[i].name)==0)
break;
}
if(i==n)
cout<<"未找到"<<endl;
else
{
leader=w[i].leader;
while(i!=-1)
{
s.push(w[i]);
i=w[i].leader;
}
}
while(!s.empty())
{
cout<<s.top().name;
s.pop();
if(!s.empty())
cout<<">";
}
return 0;
}
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <deque>
using namespace std;
int main()
{
deque<string> deq;
char ch[200];
gets(ch);
int find=0;
string name_find;
char ch2[100];
gets(ch2);
int i=0;
while(ch2[i]!='\0')
{
name_find+=ch2[i];
i++;
}
i=0;
string name;
int left=0;
int right=0;
while(ch[i]!='\0')
{
if(ch[i]==')' || ch[i]==',')
{
if(!deq.empty())
deq.pop_back();
if(ch[i]==')')
right++;
}
else if(ch[i]=='(')
{
left++;
}
else
{
while(ch[i]!='\0' && ch[i]!='(' && ch[i]!=')' && ch[i]!=',')
{
name+=ch[i];
i++;
}
i--;
deq.push_back(name);
if(name==name_find)
{
find=1;
break;
}
name.erase(name.begin(),name.end());
}
i++;
}
if(find==1)
{
while(!deq.empty())
{
cout<<deq.front();
if(deq.front()!=name_find)
cout<<">";
deq.pop_front();
}
}
else
{
cout<<"No Such Name"<<endl;
}
}