์ด ํฌ์คํ
์ ์ฟ ํก ํํธ๋์ค ํ๋์ ์ผํ์ผ๋ก, ์ด์ ๋ฐ๋ฅธ ์ผ์ ์ก์ ์์๋ฃ๋ฅผ ์ ๊ณต๋ฐ์ ์ ์์ต๋๋ค.
First of all, This fuckin' problem doesn't give a importance to ability of solving a problem. It's rather fucusing on how properly demonstrate on a display. I almost spend 3hours to make it appropriate for displaying, and it was just 30minutes to figure out the method. I'll show you a code even if this possibly spoil your creativity. (or Leave this place haha) ๋จผ์ ์ด ๋งํ ๋ฌธ์ ํธ๋๋ฐ ๋ด ๋ฌธ์ ํด๊ฒฐ ๋ฅ๋ ฅ๋ณด๋ค๋ ์ด๋ป๊ฒ ํ๋ฉดํ์์ ๋ง๊ฒ ์ถ๋ ฅํ ๊น๊ฐ ๋ ๊ด๊ฑด์ด์๋ค. ํ 3์๊ฐ์ ๋ ๋ค์๋๋ฐ 30๋ถ์ ๋๋ ์ด๋ป๊ฒํ๋ฉด ๋ฌธ์ ๋ฅผ ํ๊น์๊ณ ๋๋จธ์ง๋ ํ์ ๋ง์ถ๋๋ผ ๋
ธ๊ฐ๋ค์ง; ;; ์์ค์ฝ๋๋ฅผ ๋ณด์ฌ๋๋ฆดํ
๋, ํ๊ณ ์๋ ์ฌ๋์ ์คํฌ์ผ์ฑ์ด ๋ ์์์ผ๋ฏ๋ก ๋ ๋์์น ใ
ใ
์์คํผ์น๊ธฐ-----
more.. less..
#include < iostream> using namespace std;//์ ์ญ๋ณ์ char ** szMatrix = NULL;//ํจ์ํค๋ void GetInfoFromString(char * szBuf);//๋ฉ์ธํจ์ int main(void ) { int nCountOfData; int i; char szBuf[256 ]; //์ผ์ด์ค๋ฅผ ์
๋ ฅ๋ฐ์ cin > > nCountOfData; for (i = 0 ; i < nCountOfData ; i++) { //๋ฌธ์์ด๋ฐ์ดํ์
๋ ฅ๋ฐ์ cin > > szBuf; cout < < "Case #" < < i+1 < < ":" < < endl; GetInfoFromString(szBuf); } return 0 ; }void GetInfoFromString(char * szBuf) { //๊ทธ๋ํ์ ๋๋น int nWidthOfGraph; nWidthOfGraph = int (strlen(szBuf)); //๊ทธ๋ํ์ ๋์ด int _nHeightOfGraph = 0 ; int nHeightMax = 0 ; int nHeightMin = 0 ; int nHeightOfGraph = 0 ; //๊ทธ๋ํ์ต๊ณ ๋์ด int i,j; bool Flag = false ; //์ต๊ณ ์ ์ฐพ๊ธฐ for (i = 0 ; i < nWidthOfGraph ; i++) { if (szBuf[i] = = 'R' ){_nHeightOfGraph++;} else if (szBuf[i] = = 'F' ){ _nHeightOfGraph--;} if (_nHeightOfGraph > = nHeightMax) nHeightMax = _nHeightOfGraph; if (_nHeightOfGraph < = nHeightMin) nHeightMin = _nHeightOfGraph; } //์ต๊ณ ์ ์ C๊ฐ ์๋ ๊ฒ์ถ ์์ผ๋ฉด ํ๋๊ทธ๋ฅผ ํธ๋ฃจ๋ก _nHeightOfGraph = 0 ; for (i = 0 ; i < nWidthOfGraph ; i++) { if (szBuf[i] = = 'R' ){_nHeightOfGraph++;} else if (szBuf[i] = = 'F' ) { _nHeightOfGraph--; } else { if ((_nHeightOfGraph = = nHeightMax) & & szBuf[i] = = 'C' ) Flag = true ; } } //์ต๊ณ ์ ์ด๋ ์ต์ ์ ์ ๊ณ์ฐํ์ฌ ๋์ด๊ณ์ผ nHeightOfGraph = (nHeightMax) - nHeightMin; //szMatrix[nHeightOfGraph][nWidthOfGraph]๋ก ๋ฐฐ์ด์์ฑ // h w w w w // h w w w w // h w w w w //y์ถ๊ทธ๋ํ๋ฅผ 1์ฆ๊ฐ /* if(szBuf[strlen(szBuf)-1] = = 'R' | szBuf[strlen(szBuf)-1] = = 'F') nHeightOfGraph+= 1; else if(szBuf[strlen(szBuf)-1] = = 'C') nHeightOfGraph+= 2; */ if (Flag = = true ) nHeightOfGraph+= 2 ; else if (nHeightMax < -(nHeightMin-3 ) )nHeightOfGraph+= 1 ; else nHeightOfGraph+= 1 ; //x์ถ๊ทธ๋ํ๋ฅผ ๋ฌธ์์ด ๊ธธ์ด๋ณด๋ค 3๋ ๋ง์ด ๊ทธ๋ ค์ค๋ค.(+ํฌํจํด์) nWidthOfGraph+= 4 ; //๋์ ํ ๋น szMatrix = new char *[nHeightOfGraph]; for (i = 0 ; i < nHeightOfGraph; i++) { szMatrix[i] = new char [nWidthOfGraph]; } //NULL์ผ๋ก ์ด๊ธฐํ(memset) for (i = 0 ; i < nHeightOfGraph ; i++) { for (j = 0 ; j < nWidthOfGraph ; j++) { szMatrix[i][j] = ' ' ; if (j = = nWidthOfGraph-1 ) szMatrix[i][j]= 0 ; } } //x,y์ถ๊ต์ฐจ์ ์ +์ฐ๊ธฐ szMatrix[nHeightOfGraph-1 ][0 ] = '+' ; //๊ทธ๋ํ y์ถ๊ทธ๋ฆฌ๊ธฐ for ( i = 0 ; i < nHeightOfGraph-1 ; i++) { szMatrix[i][0 ] = '| ' ; } //๊ทธ๋ํ x์ถ๊ทธ๋ฆฌ๊ธฐ for ( i = 1 ; i < nWidthOfGraph-1 ; i++) { szMatrix[nHeightOfGraph-1 ][i] = '-' ; } //๊ทธ๋ํ ์ฐ๊ธฐ int nHeightTemp = nHeightOfGraph -2 +nHeightMin ; int nWidthTemp = nWidthOfGraph -3 ; for (i = 0 ; i < int (strlen(szBuf)) ; i++) { //์ค๋ฅผ๊ฒฝ์ฐ ์ฐ๊ณ ๋์ด ์ฆ๊ฐ if (szBuf[i] = = 'R' ) { szMatrix[nHeightTemp][i+2 ] = '/' ; nHeightTemp--; } //์ ์ง๋ ๊ฒฝ์ฐ ์ฐ๊ณ ๋์ด ๊ณ ๋๋ก else if (szBuf[i] = = 'C' ) szMatrix[nHeightTemp][i+2 ] = '_' ; //๋ด๋ฆด๊ฒฝ์ฐ ์ฐ๊ณ ๋์ด ๊ฐ์ else if (szBuf[i] = = 'F' ) { nHeightTemp++; szMatrix[nHeightTemp][i+2 ] = '\\' ; } } //์ถ๋ ฅํด์ฃผ๊ธฐ for (i = 0 ; i < nHeightOfGraph; i++) { cout < < szMatrix[i] < < endl; } cout < < endl; //๋ฉ๋ชจ๋ฆฌ๋ฅผ ํด์ ํด์ฃผ์. for (i = 0 ; i < nHeightOfGraph; i++) { delete [] szMatrix[i]; } delete [] szMatrix; }
less..