2014年北理复试上机题

2014年北理复试上机题

#include <cstdio>


void Print(int a[],int n)
{
	for(int i=0;i<n;i++)
		printf("%d ",a[i]);
	printf("\n");
}

int main()
{
	int lastest[3];
	int i,n=0,temp;
	while(1)
	{
		printf("请输入(输入-1退出):\n");
		scanf("%d",&temp);
		if(temp==-1)
			break;
		for(i=0;i<n;i++)
		{
			if(lastest[i]==temp)
				break;
		}
		if(i==n)     //未找到相同的
		{
			if(n<3)
				n++;
			
			for(i=n;i>=1;i--)
			{
				lastest[i]=lastest[i-1];
			}
			lastest[i]=temp;

		}
		Print(lastest,n);

	}

}

 

2014年北理复试上机题 

#include <cstdio>


void Print(int a[],int n)
{
	for(int i=0;i<n;i++)
		printf("%d ",a[i]);
	printf("\n");
}

int main()
{

	int lastest[3];
	int i,n=0,temp;
	while(1)
	{
		printf("请输入(输入-1退出):\n");
		scanf("%d",&temp);
		if(temp==-1)
			break;
		for(i=0;i<n;i++)
		{
			if(lastest[i]==temp)
				break;
		}
		if(i==n)     //未找到相同的
		{
			if(n<3)
				n++;
			
			for(i=n;i>=1;i--)
			{
				lastest[i]=lastest[i-1];
			}
			lastest[i]=temp;

		}
		else
		{
			for(;i>=1;i--)
			{
				lastest[i]=lastest[i-1];
			}
			lastest[i]=temp;
		}
		Print(lastest,n);

	}

	return 0;
}

 

2014年北理复试上机题 

#include<cstdio>
#include<stack>
using namespace std;

int main()
{
	char c,nl=0,n=0;
	c=getchar();
	while(c!='\n')
	{
		if(c=='(')
			nl++;
		if(c==')')
		{
			nl--;
			n++;
		}
		c=getchar();
	}
	printf("%d",n);

	return 0;


}