2011年北理复试上机题

 

#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;
		
	}


}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值