2011年北理复试上机题

 

#include 
#include 
#include 
using namespace std;

int main()
{
	string str;
	set se;
	char c;
	int n;

	while(1)
	{
		cin>>str;
		se.insert(str);
		c=getchar();
		if(c=='\n')
			break;
	}
	n=0;

	for(set::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<
#include 
#include 
#include 
#include 
#include 
using namespace std;
int main()
{
	string str;
	set s;
	map ma;

	while(cin>>str)
	{
		s.insert(str);

	}
	for(set::iterator it=s.begin();it!=s.end();it++)
	{
		ma[(*it)[0]]++;
	}

	for(map::iterator m=ma.begin();m!=ma.end();m++)
	{
		cout<first<second<

 

#include 
#include 
#include 
#include 
using namespace std;


bool cmp(string a,string b)
{
	return a vi;
	while(1)
	{
		cin>>str;
		vi.push_back(str);
		c=getchar();
		if(c=='\n')
			break;
	}
	sort(vi.begin(),vi.end(),cmp);
	for(vector::iterator it=vi.begin();it!=vi.end();it++)
	{
		cout<<(*it)<<"  ";
	}
	cout<
#include 
#include 
#include 
#include 
#include 

using namespace std;
int main()
{
	vector vi;
	string str;
	while(cin>>str)
	{
		vi.push_back(str);

	}
	sort(vi.begin(),vi.end());
	for(vector::iterator it=vi.begin();it!=vi.end();it++)
	{
		cout<<(*it)<<"  ";
	}
	cout<

 

2011年北理复试上机题_第1张图片

(aaaa(bbbb(cccc,dddd),eeee(ffff)))

#include 
#include 
#include 
#include 
#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 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<<"请输入一个姓名"<>a;
	for(i=0;i";

	}
	return 0;

}
#include 
#include 
#include 
#include 
#include 
using namespace std;

int main()
{
	deque 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.pop_front();

		}
	}
	else
	{
		cout<<"No Such Name"<

 

 

你可能感兴趣的:(考研,上机)