結果

問題 No.39 桁の数字を入れ替え
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-05-07 22:46:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,724 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 32,764 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-12 16:14:51
合計ジャッジ時間 1,016 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,356 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define READ_BUFSIZE ( 1024 )
#define READ_DELIMITER ( " " )


//標準入力取得(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;
}

void swap(char &i, char &j)
{
	char k = i;
	i = j;
	j = k;

}

int main(int argc, char *argv[]) 
{
	char szRead[READ_BUFSIZE] = "";
	//int OutList[1] = { 0 };
	char* pOutList[2] = {0};

	split( szRead, READ_BUFSIZE, READ_DELIMITER, pOutList);
	//int N = atoi(pOutList[0] );
	
	char szChar[10] = "";
	strcpy(szChar, pOutList[0]);

	char max = 0;
	int maxidx = 0;
	for (int i = 0; szChar[i]; i++)
	{
		if( max <= szChar[i])
		{
			max = szChar[i];
			maxidx = i;
		}
	}

	swap( szChar[0], szChar[maxidx]);

	printf("%s\n", szChar);


	return 0;

}

0