Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

循环模拟,0ms,附代码

Posted by guxiguxi at 2017-11-02 17:37:54 on Problem 1099 and last updated at 2017-11-02 17:44:37
#include <iostream>

using namespace std;

const int MAX = 12;

int main() 
{
	int n, k = 1, a[MAX][MAX];
	bool f[MAX];
	
	while(cin>>n && n)
	{
		for(int i = 1; i <= n; ++i)
		{
			f[i] = false;
			for(int j = 1; j <= n; ++j)
			cin>>a[i][j];
		}
		
		cout<<"Case "<<k++<<":"<<endl<<endl;
		
		int s = 4 * n + 3, e = s;
		while(s--) cout<<"*";
		cout<<endl;
		
		for(int i = 1; i <= n; ++i)
		{
			bool flag = false;
			//第1行
			cout<<"*";
			for(int j = 1; j <= n; ++j)
			{
				if(j != 1) cout<<" ";
				if(a[i][j] == 1) 
				{
					f[j] = true; 
					flag = true;
					cout<<"H-O-H";
				}
				else if(a[i][j] == 0)
				{
					if(!flag) cout<<"H-O";
					else cout<<"O-H";
				}
				else if(a[i][j] == -1)
				{
					f[j] = false;
					flag = false;
					cout<<"O";
				}
			}
			cout<<"*"<<endl;
			if(i == n) break;
			//第2行
			cout<<"*";
			for(int j = 1; j <= n; ++j)
			{
				if(j == 1) cout<<"  "; 
				else cout<<"   ";
				if(a[i][j] == 1) 
				{
					cout<<" ";
				}
				else if(a[i][j] == 0)
				{
					if(!f[j]) cout<<"|";
					else cout<<" ";
				}
				else if(a[i][j] == -1)
				{
					cout<<"|";
				}
				if(j == n) cout<<"  ";
			}
			//第三行
			cout<<"*"<<endl<<"*";
			
			for(int j = 1; j <= n; ++j)
			{
				if(j == 1) cout<<"  "; 
				else cout<<"   ";
				
				cout<<"H";
				
				if(j == n) cout<<"  ";
			}
			//第四行
			cout<<"*"<<endl<<"*";
			
			for(int j = 1; j <= n; ++j)
			{
				if(j == 1) cout<<"  "; 
				else cout<<"   ";
				
				if(a[i][j] == -1) cout<<" ";
				else 
				{
					if(f[j]) cout<<"|";
					else cout<<" ";
				}
				if(j == n) cout<<"  ";
			}
			cout<<"*"<<endl;
		}
		while(e--) cout<<"*";
		cout<<endl<<endl;
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator