UVa Problem Solution: 10189 - Minesweeper
2008-10-24 13:49
591 查看
Straight forward method. I did not work out a funnier solution.
Code:
/*************************************************************************
* Copyright (C) 2008 by liukaipeng *
* liukaipeng at gmail dot com *
*************************************************************************/
/* @JUDGE_ID 00000 10189 C "Minesweeper" */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#define MAX 102
int around(int mat[][MAX], int n, int m)
{
return mat[n-1][m-1] + mat[n-1][m] + mat[n-1][m+1]
+ mat
[m-1] + mat
[m+1]
+ mat[n+1][m-1] + mat[n+1][m] + mat[n+1][m+1];
}
int main(int argc, char *argv[])
{
#ifndef ONLINE_JUDGE
char in[256];
char out[256];
strcpy(in, argv[0]);
strcat(in, ".in");
strcpy(out, argv[0]);
strcat(out, ".out");
close(0);
open(in, O_RDONLY);
close(1);
open(out, O_WRONLY | O_CREAT, 0600);
#endif
int mat[MAX][MAX];
int n, m, i, j, f = 1;
char c;
for (scanf("%d %d", &n, &m); n != 0 && m != 0; scanf("%d %d", &n, &m)) {
if (f != 1)
putchar('/n');
bzero(mat, MAX*MAX*sizeof(int));
c = getchar();
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
c = getchar();
if (c == '*') mat[i][j] = 1;
else if (c == '.') mat[i][j] = 0;
}
c = getchar();
}
printf("Field #%d:/n", f++);
for (i = 1; i <= n; ++i) {
for (j= 1; j <= m; ++j) {
if (mat[i][j] == 1) putchar('*');
else printf("%d", around(mat, i, j));
}
putchar('/n');
}
}
return 0;
}
Code:
/*************************************************************************
* Copyright (C) 2008 by liukaipeng *
* liukaipeng at gmail dot com *
*************************************************************************/
/* @JUDGE_ID 00000 10189 C "Minesweeper" */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#define MAX 102
int around(int mat[][MAX], int n, int m)
{
return mat[n-1][m-1] + mat[n-1][m] + mat[n-1][m+1]
+ mat
[m-1] + mat
[m+1]
+ mat[n+1][m-1] + mat[n+1][m] + mat[n+1][m+1];
}
int main(int argc, char *argv[])
{
#ifndef ONLINE_JUDGE
char in[256];
char out[256];
strcpy(in, argv[0]);
strcat(in, ".in");
strcpy(out, argv[0]);
strcat(out, ".out");
close(0);
open(in, O_RDONLY);
close(1);
open(out, O_WRONLY | O_CREAT, 0600);
#endif
int mat[MAX][MAX];
int n, m, i, j, f = 1;
char c;
for (scanf("%d %d", &n, &m); n != 0 && m != 0; scanf("%d %d", &n, &m)) {
if (f != 1)
putchar('/n');
bzero(mat, MAX*MAX*sizeof(int));
c = getchar();
for (i = 1; i <= n; ++i) {
for (j = 1; j <= m; ++j) {
c = getchar();
if (c == '*') mat[i][j] = 1;
else if (c == '.') mat[i][j] = 0;
}
c = getchar();
}
printf("Field #%d:/n", f++);
for (i = 1; i <= n; ++i) {
for (j= 1; j <= m; ++j) {
if (mat[i][j] == 1) putchar('*');
else printf("%d", around(mat, i, j));
}
putchar('/n');
}
}
return 0;
}
相关文章推荐
- UVa Problem 10189 Minesweeper (扫雷)
- UVa Problem 10189 Minesweeper (扫雷)
- Problem B: Minesweeper (Uva 10189)
- UVa 10189 Problem: Minesweeper (PC 110102)
- UVa Problem 10189 Minesweeper (扫雷)
- uva 10189 Minesweeper
- Minesweeper PC/UVa IDs: 110102/10189, Popularity: A,Success rate: high Level: 1
- UVa Problem Solution: 10033 - Interpreter
- UVa Problem Solution: 10252 - Common Permutation
- UVa Problem Solution: 10138 - CDVII
- UVa Problem Solution: 10018 - Reverse and Add
- UVa Problem Solution: 10213 - How Many Pieces of Land?
- UVA_10189_Minesweeper
- UVa 10189 - Minesweeper
- UVA 10189 -Minesweeper
- uva 10189 Minesweeper
- UVa Problem Solution: 10196 - Check The Check
- UVa Problem Solution: 10149 - Yahtzee
- UVa Problem Solution: 850 - Crypt Kicker II
- UVa Problem Solution: 120 - Stacks of Flapjacks