1、题目:

算法与数据结构实验题 2.4 排队

2、代码:

#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int a[10001];
	int i,j;
	for(i=0;i<10000;i++)
	{
		a[i]=i+2;
	}
	for(j=0;j<10000;j++)
	{
		int counts=0;
		if(a[j]!=0)
		{
			for(i=j+1;i<10000;i++)
			{
				if(a[i]!=0)
				{
					counts++;
				}
				if(counts==a[j])
				{
					a[i]=0;
					counts=0;
				}
				
			}
		}
	}
	int count=0;
	for(int k=0;k<10000;k++)
	{
		if(a[k]!=0)
		{
			count++;
		}
		if(count==n)
		{
			printf("%d\n",a[k]);
			break;
		}
	}
	return 0;
}

相关文章:

  • 2021-10-04
  • 2021-06-15
  • 2021-06-23
  • 2021-05-19
  • 2022-02-19
  • 2021-10-15
  • 2021-11-29
  • 2021-04-22
猜你喜欢
  • 2022-01-15
  • 2021-08-28
  • 2021-10-04
  • 2021-05-16
  • 2022-02-05
  • 2021-06-24
相关资源
相似解决方案