#1094 : Lost in the City by C solution
描述
Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north.
Fortunately, Little Hi has a map of the city. The map can be considered as a grid of N*M blocks. Each block is numbered by a pair of integers. The block at the north-west corner is (1, 1) and the one at the south-east corner is (N, M). Each block is represented by a character, describing the construction on that block: '.' for empty area, 'P' for parks, 'H' for houses, 'S' for streets, 'M' for malls, 'G' for government buildings, 'T' for trees and etc.
Given the blocks of 3*3 area that surrounding Little Hi(Little Hi is at the middle block of the 3*3 area), please find out the position of him. Note that Little Hi is disoriented, the upper side of the surrounding area may be actually north side, south side, east side or west side.
输入
Line 1: two integers, N and M(3 <= N, M <= 200).
Line 2~N+1: each line contains M characters, describing the city's map. The characters can only be 'A'-'Z' or '.'.
Line N+2~N+4: each line 3 characters, describing the area surrounding Little Hi.
输出
Line 1~K: each line contains 2 integers X and Y, indicating that block (X, Y) may be Little Hi's position. If there are multiple possible blocks, output them from north to south, west to east.
- 样例输入
-
8 8
...HSH..
...HSM..
...HST..
...HSPP.
PPGHSPPT
PPSSSSSS
..MMSHHH
..MMSH..
SSS
SHG
SH. - 样例输出
-
5 4
代码实现:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int compare(char** s1, int i, int j, char surround[][])
{
for (int a = i; a< + i; a++)
for (int b = j; b< + j; b++)
{
if (s1[a][b] != surround[a - i][b - j])
return ;
} return ;
}
int main()
{
int n = , m = ;
scanf("%d %d", &n,&m);
getchar();
char** map = (char**)malloc(sizeof(char)*n);
for (int i = ; i<n; i++)
{
map[i] = (char*)malloc(sizeof(char)*m);
fgets(map[i], m+, stdin);
getchar();
}
char surround[][] = { };
for (int i = ; i<; i++)
{
fgets(surround[i], , stdin);
getchar();
}
char surround1[][] = { };
char surround2[][] = { };
char surround3[][] = { };
char position = surround[][];
for (int i = ; i<; i++)
{
for (int j = ; j<; j++)
{
surround1[ - j][i] = surround[i][j];
}
}
for (int i = ; i<; i++)
{
for (int j = ; j<; j++)
{
surround2[ - j][i] = surround1[i][j];
}
}
for (int i = ; i<; i++)
{
for (int j = ; j<; j++)
{
surround3[ - j][i] = surround2[i][j];
}
}
for (int i = ; i<n - ; i++)
{
for (int j = ; j<m - ; j++)
{ if (map[i][j] == position)
{
if (compare(map, i - , j - , surround))
{
printf("%d %d\n", i + , j + );
continue;
}
if (compare(map, i - , j - , surround1))
{
printf("%d %d\n", i + , j + );
continue;
}
if (compare(map, i - , j - , surround2))
{
printf("%d %d\n", i + , j + );
continue;
}
if (compare(map, i - , j - , surround3))
{
printf("%d %d\n", i + , j + );
continue;
}
}
}
}
return ;
}
问题:
使用Visual Studio编译运行样例结果正确,但是提交代码通过G++运行会出现Wrong Answer,若知道原因的话还望请留言告知!
最新文章
- Unity中各类物理投射性能横向比较
- Android中Bitmap和Drawable
- MSP430F5438点亮led
- 【转】ButterKnife基本使用--不错
- 申请免费的SSL证书(Win7,PowerShell,Let&#39;s Encrypt)
- php的2种域名转向写法
- UART串口通讯协议
- 14-使用glusterfs做持久化存储
- 【javascript】获取 格式化时间
- Linux基础命令---杀死进程pkill
- maven的传递性依赖
- 2018.07.03 POJ 3348 Cows(凸包)
- python标准库介绍——2 os.path模块详解
- Windows10下安装python(配置环境变量)
- TinyURL
- 【Java学习经历系列-1】19岁的我,没遇见生命中的她,却遇见了java
- js中立即执行函数写法理解
- 【转】 Pro Android学习笔记(七四):HTTP服务(8):使用后台线程AsyncTask
- thinkphp5命令行访问
- [转载]php 数组 类对象 值传递 引用传递 区别