Submission #00842


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<stdio.h>
#include<string.h>
typedef struct{int x, y;}Hcoord; // 'h'の座標格納用
const int dx[4] = {1, 0, -1, 0}; // それぞれ0番地から
const int dy[4] = {0, 1, 0, -1}; //   右、下、左、上を指す
const char s[] = "elloworld"; // "helloworld"を見つけたかどうかの確認用
int main(){
char str[100][101]; // 散らばる文字を格納
int n, m; // n * mの文字
int i, j; // for文用
Hcoord hc[10000]; // 'h'の座標格納用
int hccnt = 0; // hcに格納されている座標の数の格納用
int len = strlen(s); // elloworldの長さ
/*入力*/
scanf("%d %d", &n, &m);
for(i = 0; i < n; i++) scanf("%s", str[i]);
/*文字'h'のある座標を記録する*/
for(i = 0; i < n; i++){
for(j = 0; j < m; j++){
if(str[i][j] == 'h'){
hc[hccnt].y = i; // iはy
hc[hccnt].x = j; // jはxに対応している。 初心者はミスしがちなので注意
hccnt++; // 'h'が見つかったので1足してあげる
}
}
}
/*文字'h'のある回数だけ4方向について調べる*/
int match;
for(i = 0; i < hccnt; i++){
for(j = 0; j < 4; j++){
match = 0; // "elloworld"を見つけ出すためのcount flugみたいな感じ
int nx = dx[j] + hc[i].x; // next_x hがある座標からの
int ny = dy[j] + hc[i].y; // next_y 4方向が格納される
if(0 <= nx && 0 <= ny && nx < m && ny < n && s[match] == str[ny][nx]){
/*ifの内容 もし配列strの範囲内で、なおかつmatch番目の文字と一致したら*/
while(match < len){
/*whileの条件文 match番目がlenの長さ超えたらhelloworldは存在するからlenまで*/
match++; // 2番目以降の文字を見るために先にmatchを++する
nx += dx[j]; // j番目の方向をみていくため
ny += dy[j]; // それぞれを足す
if(s[match] != str[ny][nx])
break;
//もし文字の一致を見ている最中に違う文字が現れれば存在しないのでbreak
//全部一致してても次の文字でbreakするのでwhileの条件文は1でもいいんじゃない
}
}
if(match >= len) break;
}
if(match >= len) break;
}
if(match >= len) printf("Homono is Criminal\n");
else printf("NA\n");
return 0;
}

ステータス

項目 データ
問題 0055 - Hello world Extreme
ユーザー名 ei1409
投稿日時 2015-07-28 10:26:27
言語 C
状態 Accepted
得点 1
ソースコード長 2464 Byte
最大実行時間 12 ms
最大メモリ使用量 3084 KB

セット

セット 得点 Cases
1 ALL 1 / 1 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
sample1_in.txt AC 10 ms 3028 KB
1
sample2_in.txt AC 10 ms 3084 KB
1
sample3_in.txt AC 12 ms 2910 KB
1
sample4_in.txt AC 12 ms 2914 KB
1
sample5_in.txt AC 9 ms 3082 KB
1