| ||||||||||
| 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 | |||||||||
这道题不就是这样子的吗,怎么会错,来看一下#include <iostream>
using namespace std;
char a[12][12];
char b[12][12];
int main() {
int i,j;
int n,k;
int c;
while(cin>>n) {
cin.ignore();
for(k=0;k<n;k++){
cin.getline(a[k],11);
}
for(k=0;k<n;k++) {
cin.getline(b[k],11);
}
for(i=0;i<n;i++) {
for(j=0;j<n;j++){
if(b[i][j]=='.') {
cout<<'.';
continue;
}
if(a[i][j]!='.'){
cout<<a[i][j];
continue;
}
c=0;
if(i-1>=0 && a[i-1][j]=='*') ++c;
if(i+1<n && a[i+1][j]=='*') ++c;
if(j-1>=0 && a[i][j-1]=='*') ++c;
if(j+1<n && a[i][j+1]=='*' )++c;
if(i-1>=0 && j-1>=0 && a[i-1][j-1]=='*') ++c;
if(i-1>=0 && j+1<n && a[i-1][j+1]=='*') ++c;
if(i+1<n && j-1>=0 && a[i+1][j-1]=='*') ++c;
if(i+1<n && j+1<n &&a[i+1][j+1]=='*') ++c;
cout<<c;
}
cout<<endl;
}
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator