Submission #8391220


Source Code Expand

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF
#define D_CHAR_MAX		70										// 最大文字数
#define D_CHAR_KIND		8										// 文字種類数

// 内部変数
static FILE *szpFpI;											// 入力
static char sc1Str[D_CHAR_MAX];									// 文字列
static int siSLen;												// 文字列長
static char sc1Ans[D_CHAR_KIND + 5];							// 解答

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 1行出力
int
fOutLine(
	char *pcpLine				// <I> 1行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 改行カット
// 戻り値:文字数
int
fCutCrLf(
	char *pcpStr				// <I> 文字列
)
{
	int i;

	for (i = 0; pcpStr[i] != '\0'; i++) {
		if (pcpStr[i] == '\n') {
			pcpStr[i] = '\0';
			break;
		}
	}

	return i;
}

// 判定
int
fJudge(
)
{
	int i;

	// 使用可能文字
	int liUNo = D_CHAR_KIND;
	char lc1Use[D_CHAR_KIND];
	memset(lc1Use, D_OFF, sizeof(lc1Use));

	// 文字列 - チェック
	int liLen = 1;
	for (i = siSLen - 1; i >= 0; i--) {

		// 使用可
		if (lc1Use[sc1Str[i] - 'A'] == D_ON) {
			liLen++;
			continue;
		}

		// 長さ - チェック
		if (liLen < 1) {
			return -1;
		}

		// 前の章へ
		liLen = 0;
		liUNo--;
		lc1Use[sc1Ans[liUNo] - 'A'] = D_ON;
		i++;
	}

	return 0;
}

// 解答 - セット
int
fSetAns(
	int piNo					// <I> 位置
	, char *pcpSet				// <I> セット済文字
)
{
	int i, liRet;

	// セット終了
	if (piNo >= D_CHAR_KIND) {
		return fJudge();
	}

	// 解答 - セット
	for (i = 0; i < D_CHAR_KIND; i++) {

		// セット済文字
		if (pcpSet[i] == D_ON) {
			continue;
		}

		// セット
		sc1Ans[piNo] = 'A' + i;
		pcpSet[i] = D_ON;

		// 下位へ
		liRet = fSetAns(piNo + 1, pcpSet);
		if (liRet == 0) {
			return 0;
		}

		// セット解除
		pcpSet[i] = D_OFF;
	}

	return -1;
}

// 実行メイン
int
fMain(
)
{
	// 文字列 - 取得
	fgets(sc1Str, sizeof(sc1Str), szpFpI);
	siSLen = fCutCrLf(sc1Str);

	// 解答 - セット
	char lc1Use[D_CHAR_KIND];
	memset(lc1Use, D_OFF, sizeof(lc1Use));
	fSetAns(0, lc1Use);

	return 0;
}

// 1回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(sc1Ans, 0, sizeof(sc1Ans));							// 解答

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%s\n", sc1Ans);
	fOutLine(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}

Submission Info

Submission Time
Task B - 残像に口紅を
User asugen0402
Language C (GCC 5.4.1)
Score 100
Code Size 3697 Byte
Status AC
Exec Time 2 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘fMain’:
./Main.c:149:2: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result [-Wunused-result]
  fgets(sc1Str, sizeof(sc1Str), szpFpI);
  ^

Judge Result

Set Name Easy All
Score / Max Score 50 / 50 50 / 50
Status
AC × 15
AC × 46
Set Name Test Cases
Easy easy-000.txt, easy-001.txt, easy-002.txt, easy-003.txt, easy-004.txt, easy-005.txt, easy-006.txt, easy-007.txt, easy-008.txt, easy-009.txt, easy-010.txt, easy-011.txt, easy-012.txt, easy-013.txt, easy-014.txt
All easy-000.txt, easy-001.txt, easy-002.txt, easy-003.txt, easy-004.txt, easy-005.txt, easy-006.txt, easy-007.txt, easy-008.txt, easy-009.txt, easy-010.txt, easy-011.txt, easy-012.txt, easy-013.txt, easy-014.txt, hard-000.txt, hard-001.txt, hard-002.txt, hard-003.txt, hard-004.txt, hard-005.txt, hard-006.txt, hard-007.txt, hard-008.txt, hard-009.txt, hard-010.txt, hard-011.txt, hard-012.txt, hard-013.txt, hard-014.txt, hard-015.txt, hard-016.txt, hard-017.txt, hard-018.txt, hard-019.txt, hard-020.txt, hard-021.txt, hard-022.txt, hard-023.txt, hard-024.txt, hard-025.txt, hard-026.txt, sample1.txt, sample2.txt, sample3.txt, sample4.txt
Case Name Status Exec Time Memory
easy-000.txt AC 1 ms 128 KB
easy-001.txt AC 1 ms 128 KB
easy-002.txt AC 1 ms 128 KB
easy-003.txt AC 1 ms 128 KB
easy-004.txt AC 1 ms 128 KB
easy-005.txt AC 1 ms 128 KB
easy-006.txt AC 1 ms 128 KB
easy-007.txt AC 1 ms 128 KB
easy-008.txt AC 1 ms 128 KB
easy-009.txt AC 1 ms 128 KB
easy-010.txt AC 1 ms 128 KB
easy-011.txt AC 1 ms 128 KB
easy-012.txt AC 1 ms 128 KB
easy-013.txt AC 2 ms 128 KB
easy-014.txt AC 1 ms 128 KB
hard-000.txt AC 1 ms 128 KB
hard-001.txt AC 1 ms 128 KB
hard-002.txt AC 1 ms 128 KB
hard-003.txt AC 1 ms 128 KB
hard-004.txt AC 2 ms 128 KB
hard-005.txt AC 1 ms 128 KB
hard-006.txt AC 1 ms 128 KB
hard-007.txt AC 1 ms 128 KB
hard-008.txt AC 1 ms 128 KB
hard-009.txt AC 1 ms 128 KB
hard-010.txt AC 1 ms 128 KB
hard-011.txt AC 1 ms 128 KB
hard-012.txt AC 1 ms 128 KB
hard-013.txt AC 1 ms 128 KB
hard-014.txt AC 1 ms 128 KB
hard-015.txt AC 1 ms 128 KB
hard-016.txt AC 1 ms 128 KB
hard-017.txt AC 1 ms 128 KB
hard-018.txt AC 1 ms 128 KB
hard-019.txt AC 1 ms 128 KB
hard-020.txt AC 1 ms 128 KB
hard-021.txt AC 1 ms 128 KB
hard-022.txt AC 1 ms 128 KB
hard-023.txt AC 1 ms 128 KB
hard-024.txt AC 1 ms 128 KB
hard-025.txt AC 1 ms 128 KB
hard-026.txt AC 1 ms 128 KB
sample1.txt AC 1 ms 128 KB
sample2.txt AC 1 ms 128 KB
sample3.txt AC 2 ms 128 KB
sample4.txt AC 1 ms 128 KB