Introduction to Programming Introduction to Algorithms and Data Structures Library of Data Structures Library of Graph Algorithms Library of Computational Geometry Library of Dynamic Programming Library of Number Theory
一筆書き出来るか,ということでグラフ作って奇数点の頂点を数えようかと思ったけど,グラフを作るなら,mapに突っ込んで 文字ずつ隣接しているか見たほうが早いと思い,そっちにした.
Code
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair
using namespace std ;
typedef long long ll ;
typedef pair < int , int > P ;
map < char , set < char > > m ;
int main () {
m [ 'A' ]. insert ( 'B' );
m [ 'A' ]. insert ( 'D' );
m [ 'B' ]. insert ( 'A' );
m [ 'B' ]. insert ( 'C' );
m [ 'B' ]. insert ( 'E' );
m [ 'C' ]. insert ( 'B' );
m [ 'C' ]. insert ( 'F' );
m [ 'D' ]. insert ( 'A' );
m [ 'D' ]. insert ( 'E' );
m [ 'D' ]. insert ( 'G' );
m [ 'E' ]. insert ( 'B' );
m [ 'E' ]. insert ( 'D' );
m [ 'E' ]. insert ( 'F' );
m [ 'E' ]. insert ( 'H' );
m [ 'F' ]. insert ( 'C' );
m [ 'F' ]. insert ( 'E' );
m [ 'F' ]. insert ( 'I' );
m [ 'G' ]. insert ( 'D' );
m [ 'G' ]. insert ( 'H' );
m [ 'H' ]. insert ( 'E' );
m [ 'H' ]. insert ( 'G' );
m [ 'H' ]. insert ( 'I' );
m [ 'I' ]. insert ( 'F' );
m [ 'I' ]. insert ( 'H' );
rep ( i , 1000 ) {
string s ;
cin >> s ;
bool flag = true ;
rep ( j , s . size () - 1 ) {
if ( m [ s [ j ]]. find ( s [ j + 1 ]) == m [ s [ j ]]. end ()) {
flag = false ;
break ;
}
}
if ( flag ) cout << s << endl ;
}
return 0 ;
}