結果

問題 No.784 「,(カンマ)」
ユーザー tsuishitsuishi
提出日時 2021-03-19 09:49:31
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,089 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 28,476 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-11 05:28:47
合計ジャッジ時間 1,241 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Yukicoder №784 「,(カンマ)」 ★
// https://yukicoder.me/problems/no/784
// ***********************
#define	str_len(a)	mystr_len_lim(a,9999)
static int mystr_len_lim(char *str,int lim){int i=0;do{if(str[i]=='\0')break;i++;}while(i<lim);return i;}
#define GETLINE(str)	do{char *p;fgets(str,sizeof(str),stdin);p=strchr(str,'\n');if(p)*p='\0';}while(0)
static int GETLINEINT(void) {char s[34];GETLINE(s);return atoi(s);}

// *********************
// *********************
char *COMMA(int inum ) {
	static char ostr[128];
	static char tmp[128];
	int	minf = 1;
	int	lnk = -1;
	char	*ip;
	char	*op;

	op = &ostr[128-1];
	if( inum < 0 ) {
		minf = -1;
		inum = inum * -1;
	}
	sprintf(tmp,"%d",inum);
	ip = &tmp[ str_len( tmp ) -1 ];
	*(op)-- = '\0';
	// start
	while( ip >= tmp ) {
		if( ++lnk >= 3 ) {
			*(op)-- = ',';
			lnk = 0;
		}
		*(op)-- = *(ip)--;
	}
	++(op);
	if( minf < 0 ) {
		*--(op) = '-';
	}
	return op;
}
// *********************
int main( void ) {
	int	i;

	i = GETLINEINT();
	printf("%s\n",COMMA(i));
}

0