⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trainreset.cpp

📁 TrainReset:there are many trains need to drive out of the station .In terms of their numbers from sm
💻 CPP
字号:
#include <iostream>

using namespace std;

void main()
{
	int s[4][13] , a[10] , top[4];
	int k = 3 , n = 9 , suc = 0 , flag = 1 , pos = 1 , need = 1;
	int i ,  tout , c , x , min , hao;

	for( i = 1; i <= k; i++ )
		top[i] = 0;
	cout<<"Please input the array:  "<<endl;
	for( i = 1; i <= n; i++ )
		cin>>a[i];
	while( flag )
	{
		if( need > n )
		{
			suc = 1;
			flag = 0;
		}
		else
		{
			if( ( pos <= n ) && ( a[pos] == need ) )
			{
				cout<<need<<endl;
				need++;
				pos++;
			}
			else
			{
				tout = 0;
				for( i = 1; i <= k; i++ )
				{
					if( ( top[i] != 0 ) && ( s[i][top[i]] == need ) )
					{
						cout<<need<<"*****"<<i<<endl;
						need++;
						tout = 1;
						top[i]--;
					}
				}
				if( !tout )
				{
					c = a[pos];
					pos++;
					min = 10;
					hao = 0;
					for( i = 1; i <= k; i++ )
					{
						if( top[i] != 0 )
						{
							x = s[i][top[i]];
							if( ( c < x ) && ( x < min ) )
							{
								min = x;
								hao = i;
							}
						}
						else if( !hao )
							hao = i;
					}
					if( !hao )
						flag = 0;
					else
					{
						top[hao]++;
						s[hao][top[hao]] = c;
					}
				}
			}
		}
	}
	if( suc )
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<"*****"<<a[pos - 1]<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -