結果

問題 No.123 カードシャッフル
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-10-19 23:30:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 1,670 bytes
コンパイル時間 245 ms
コンパイル使用メモリ 34,140 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-13 12:45:33
合計ジャッジ時間 1,085 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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, int *palOutList) {
	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)
		{
			*palOutList = atoi(pszToken);
			lNum++;
			//	        pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
			pszToken = strtok(NULL, pszDelim);
			palOutList++;
		}
	}
	return lNum;
}


void shuffle( char* pn, int Num, int shuffle)
{
	char top = *(pn + shuffle-1);

	for (int i = shuffle-2; i >= 0; i--)
	{
		*(pn + i + 1) = *(pn + i);
	}
	*pn = top;

}

int main(int argc, char *argv[])
{
	int temp[2] = { 0 };
	int N = 0;
	int M = 0;
	
	char sTemp[1000] = "";
	split(sTemp, 1000, " ", temp);
	N = temp[0];
	M = temp[1];

	int *pA = new int[M];
	char *psTemp = new char[M * 2+ M + 1];
	split(psTemp, M * 2 + M + 1, " ", pA);

	char n[50] = "";
	for (int i = 0; i < N; i++) n[i] = i+1;

	for (int j = 0; j < M; j++)
	{
		shuffle(n, N, pA[j]);
	}

	printf("%d\n", n[0]);

	delete [] pA;

	return 0;

}

0