...
int main()
{
...
int caseno=0;
for(;;)
{
cin>>row>>col;
if(row==0 && col==0)
{
break;
}
if(caseno++) cout<<endl; // I have added this line
...
//cout<<endl; // Removed this line
}
return 0;
}
i have this common problem, it shows me "presentation error" on the http://www.programming-challenges.com/. Now, I'm waiting for the results from UVa
i tried and to put an empty line after inputting the line and row, but it doesn't work like that either..
#include <iostream>
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
int main()
{
char grid[101][101];
int length, width;
int field = 1;
std::cin >> length >> width;
std::cin.get();
while (length != 0 && width != 0)
{
std::cin.get();
if (field > 1)
std::cout << std::endl;
for (int i = 0; i < length; ++i)
std::cin.getline(grid[i], 100);
std::cout << "Field #" << field << ":" << std::endl;
for (int i = 0; i < length; ++i)
{
for (int j = 0; j < width; ++j)
{
if (grid[i][j] == '*')
std::cout << '*';
else
{
int hint = 0;
for (int a = MAX(0, i - 1); a <= MIN(length - 1, i + 1); ++a)
for (int b = MAX(0, j - 1); b <= MIN(width - 1, j + 1); ++b)
if (grid[a][b] == '*')
++hint;
std::cout << hint;
}
}
std::cout << std::endl;
}
std::cin >> length >> width;
++field;
}
return 0;
}
Sorry everybody. I am new user here. I've started Minesweeper, but by whatever reason the program results in Presentation Error. Could anybody spend a little time to figure it for me? It takes me one night, and I was tired because of this tricky mistake
#include <cstdlib>
#include <iostream>
#include <string.h>
using namespace std;
int numb(int i, int j, char str[1000][1000], int n, int m)
{
int r=0;
if (str[i][j]=='*') return -1;
for (int k=-1; k<=1; k++)
for (int h=-1; h<=1; h++)
if (k!=0|| h!=0)
{
int px=i+k;
int py=j+h;
if (px>=0&&px<n && py>=0&&py<=m && str[px][py]=='*') r++;
}
return r;
}
void process(int a, char str[1000][1000], int n, int m)
{
cout<<"Field #"<<a<<": "<<endl;
for (int i=0; i<n; i++)
{
for (int j=0; j<m; j++)
{
int k=numb(i,j,str,n,m);
if (k==-1) cout<<"*"; else cout<<k;
}
cout<<endl;
}
}
int main(int argc, char *argv[])
{
int numf=1;
int m,n;
while (true)
{
cin>>n>>m;
char str[1000][1000];
if (m==0 && n==0) return 1;
for (int i=0; i<n; i++)
{
cin>>str[i];
}
process(numf, str,n,m);
numf++;
cout<<endl;
}
return 1;
}
#include <iostream>
using namespace std;
char arena[101][101];
void clearArena(int m, int n);
void setArena(int m, int n);
void printArena(int m, int n);
void countMines(int m, int n);
int main(){
int m, n, count = 1;
while(1){
cin >> m >> n;
if(count != 1)cout << endl;
if(m == 0 || n == 0)
break;
clearArena(m,n);
setArena(m,n);
countMines(m,n);
cout << "Field #" << count << ":\n";
count++;
printArena(m,n);
}
return 0;
}
void countMines(int m, int n){
int x, y, tempX, tempY;
int count;
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
if(arena[i][j] == '*')
continue;
count = 0;
x = j - 1;
y = i - 1;
for(int a = 0; a < 3; a++){
tempY = y + a;
if(tempY < 0 || tempY >= m)
continue;
for(int b = 0; b < 3; b++){
tempX = x + b;
if(tempX < 0 || tempX >= n)
continue;
if(arena[tempY][tempX] == '*')
count++;
}
}
arena[i][j] = '0' + count;
}
}
}
void setArena(int m, int n){
for(int i = 0; i < m; i++){
cin >> arena[i];
}
}
void clearArena(int m, int n){
m++;
n++;
for(int i = 0; i < m; i++)
for(int j = 0; j < n; j++)
arena[i][j] = '\0';
}
void printArena(int m, int n){
for(int i = 0; i < m; i++)
cout << arena[i] << endl;
//cout << "\n";
}
Hello to all,
i'm getting wa. after trying all the possible input cases i couldn't find what's wrong.
i've tried all the inputs in the previous posts. all outputs are ok.
i've tried hours.
i'm wondering what the program should do when either m or n is 0.
because the problem says to terminate only when m=n=0.
here's my code:
Hey all,
I tested all of test data with my program and every one of them is correct!!! But I still get WA! I double checked each line of my code and found nothing wrong about it! Could you please take a look at it and find my bug please?
Thanks in advance. I appreciate your help.