結果
| 問題 | No.784 「,(カンマ)」 | 
| コンテスト | |
| ユーザー |  tsuishi | 
| 提出日時 | 2021-03-19 09:49:31 | 
| 言語 | C (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1 ms / 2,000 ms | 
| コード長 | 1,089 bytes | 
| コンパイル時間 | 404 ms | 
| コンパイル使用メモリ | 29,312 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-17 18:59:34 | 
| 合計ジャッジ時間 | 739 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 10 | 
ソースコード
#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));
}
            
            
            
        