| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
循环模拟,0ms,附代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator