📄 toj_2883.cpp
字号:
/*2883. City Mapping Time Limit: 1.0 Seconds Memory Limit: 65536KTotal Runs: 282 Accepted Runs: 158Long long ago, Hawk City was a small but the richest city on our continent. The king of the city, named Cai Niao Hawk(C-N-Hawk), built many convenient streets for citizens. Nowadays, although it is fallen to ruin, the design of the streets of Hawk City is still interesting. People find it significant to research the layout of the old city.The Hawk City is a rectangle and the size is M * N decametres(1 decametre = 10 metres). The streets are always goes horizontally or vertically. An explorer will start from the northwest corner of Hawk City. He will tell you his path by interphone, and your job is mapping the city.When the explorer turns left or right, he will report you his path in these 4 formats of instructions: North x walk x decametres to the north(x < M) South x walk x decametres to the south(x < M) East x walk x decametres to the east (x < N) West x walk x decametres to the west (x < N)Each instruction denotes one street that he walks. Please use his information to map the streets, using '-' to denote the horizontal streets, '|' to denote the vertical streets, and '+' to denote the crossings. Please fill the other areas with dots('.').InputThere are serveral test scenarios. Each scenario begins with three positive integer M, N, I. 1 ≤ M, N, I ≤ 200. M, N is the size of the city, and I is the number of instructions. Then I lines follow, each contains one instruction. The explorer guaranteed that he won't make a U-turn. He may reach some crossings several times but he won't walk a street twice. Since he report every street only once, there won't be two instructions with the same direction. Of course, the explorer will come back to the starting position after I instructions.The input will terminate by M = N = I = 0.OutputThe output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Please mapping the Hawk City with M lines of strings, and each line must contain exactly N characters. The horizontal streets should be mapped by '-' and vertical streets should be mapped by '|'. Both the turnings and the crossings should be mapped by '+'.Sample Input5 5 4South 2East 2North 2West 220 20 6East 10South 15East 5North 7West 15North 80 0 0Sample OutputScenario #1:+-+..|.|..+-+............Scenario #2:+---------+.........|.........|.........|.........|.........|.........|.........|.........|.........|.........|.........|.........|.........|.........|.........+---------+----+..............|....|..............|....|..............|....|..............|....|..............|....|..............|....|..............+----+....................................................................................Source: TJU Team Selection Contest 6*/#include<cstdio>#include<cstring>int const MAX = 210;void printfMap( char map[][ MAX ] , int m , int n ){ int i , j; for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { putchar( map[ i ][ j ] ); } putchar( '\n' ); }}int main(){ int m , n , nDirection , nStep , nScenario , i , j , k , x , y , dx , dy; char map[ MAX ][ MAX ] , direction[ 10 ] , road; char mapA[ 1000000000 ]; for ( nScenario = 1; scanf( "%d%d%d" , &m , &n , &nDirection ) != EOF && m != 0 && n != 0 && nDirection != 0; nScenario++ ) { memset( map , '.' , MAX * MAX * sizeof( char ) ); map[ 0 ][ 0 ] = '+'; x = 0; y = 0; for ( i = 0; i < nDirection; i++ ) { scanf( "%s%d" , direction , &nStep ); if ( strcmp( direction , "North" ) == 0 ) { dx = 0; dy = -1; road = '|'; } else if ( strcmp( direction , "East" ) == 0 ) { dx = 1; dy = 0; road = '-'; } else if ( strcmp( direction , "South" ) == 0 ) { dx = 0; dy = 1; road = '|'; } else if ( strcmp( direction , "West" ) == 0 ) { dx = -1; dy = 0; road = '-'; } for ( j = 0; j < nStep - 1; j++ ) { x += dx; y += dy; if ( map[ y ][ x ] == '.' ) map[ y ][ x ] = road; else if ( map[ y ] [ x ] == '-' || map[ y ][ x ] == '|' ) map[ y ][ x ] = '+'; } x += dx; y += dy; map[ y ][ x ] = '+'; } printf( "Scenario #%d:\n" , nScenario ); printfMap( map , m , n ); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -