結果

問題 No.264 じゃんけん
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-03-27 23:27:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,073 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 26,876 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 14:51:31
合計ジャッジ時間 983 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:10:29: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define PRINT_DREW ( "Drew" )
                             ^
main.cpp:97:18: note: in expansion of macro ‘PRINT_DREW’
     psPrintBuf = PRINT_DREW;
                  ^~~~~~~~~~
main.cpp:8:27: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define PRINT_WON ( "Won" )
                           ^
main.cpp:100:18: note: in expansion of macro ‘PRINT_WON’
     psPrintBuf = PRINT_WON;
                  ^~~~~~~~~
main.cpp:9:29: warning: ISO C++ forbids converting a string constant to ‘char*’ [-Wwrite-strings]
 #define PRINT_LOST ( "Lost" )
                             ^
main.cpp:102:18: note: in expansion of macro ‘PRINT_LOST’
     psPrintBuf = PRINT_LOST;
                  ^~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define READ_BUFSIZE ( 10 )
#define READ_DELIMITER ( " " )

#define PRINT_WON ( "Won" )
#define PRINT_LOST ( "Lost" )
#define PRINT_DREW ( "Drew" )


//標準入力取得(1行)

int GetStdin( char* pszStr, int lMaxLen )
{
	int lLen = 0;

    memset( pszStr, 0, lMaxLen );
    if( fgets( pszStr, lMaxLen, stdin ) )
    {
	    lLen = strlen( pszStr );
	    if( lLen >= 1 )
	    {
			if( pszStr[ lLen - 1 ] == 0x0A )
			{
				pszStr[ lLen - 1 ] = 0;
				lLen--;
			}
		}
	}
	
	return( lLen );
}


//標準入力を取得
//区切り文字で区切られている文字列を取り出す
//取り出した文字列のポインタをポインタ配列にセットする
int split(char *pszStr, int lStrMax, const char *pszDelim, char *apszOutList[]) {
    char *pszToken;
    int count = 0;
    char *pszNext_token = 0;
	int lLen = 0;
	int lNum = 0;

    memset( pszStr, 0, lStrMax );
    lLen = GetStdin( pszStr, lStrMax );
    
	if( lLen > 0 )
	{

	    pszToken = strtok( pszStr, pszDelim );

	    while ( pszToken != NULL ) 
	    {
            apszOutList[ lNum ] = pszToken;
			lNum++;
//	        pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
		    pszToken = strtok( NULL, pszDelim );
	    }
	}
    return lNum;
}




int main(int argc, char *argv[]) 
{
	// ぐー   0
	// ちょき 1
	// ぱー   2

	char szRead[READ_BUFSIZE] = "";
	char* psOutbuf[2] = { 0 };

	char* psPrintBuf = 0;

	//自分が勝つ場合の相手の定義
	int lWin[] = { 1,  //自分はぐー
	               2,  //自分はちょき
	               0};  //自分はパー


	int lNum = split( szRead, READ_BUFSIZE, READ_DELIMITER, psOutbuf );

	if( lNum >= 2 )
	{
		int lJibun = atoi( psOutbuf[0] );
		int lAite = atoi( psOutbuf[1] );

		if( lJibun >= 0 &&  lJibun <= 2 &&
			lAite >= 0 && lAite <= 2 )
		{
			if( lJibun == lAite )
				psPrintBuf = PRINT_DREW;

			else if( lWin[ lJibun ] == lAite )
				psPrintBuf = PRINT_WON;
			else
				psPrintBuf = PRINT_LOST;

			printf( "%s\n", psPrintBuf );
		}

	}


	return 0;

}

0