結果

問題 No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
ユーザー mafuyu-akimafuyu-aki
提出日時 2017-03-26 18:55:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 2,136 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 27,100 KB
実行使用メモリ 12,788 KB
最終ジャッジ日時 2023-09-20 11:05:47
合計ジャッジ時間 1,437 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 6 ms
4,376 KB
testcase_09 AC 7 ms
4,632 KB
testcase_10 AC 19 ms
10,808 KB
testcase_11 AC 18 ms
10,764 KB
testcase_12 AC 20 ms
11,056 KB
testcase_13 AC 20 ms
11,280 KB
testcase_14 AC 21 ms
11,640 KB
testcase_15 AC 20 ms
11,804 KB
testcase_16 AC 22 ms
12,788 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


//文字列長取得関数
int GetStrLen( char* psStr, char byStop, int lMaxLen )
{
		
	int i = 0;
	
	for( i = 0; i < lMaxLen; i++ )
	{
		if( *( psStr + i ) == byStop )
			break;
	}
	
	return( i );
}

//標準入力取得(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[]) {
unsigned long long int split( int lCount ) {
    char *pszToken;
    int count = 0;
    char *pszNext_token = 0;
	int lLen = 0;
	int lNum = 0;


	int lStdinLen = lCount * 20 + lCount;
	char* pszStdin = ( char* )malloc( lStdinLen );

	memset( pszStdin, 0, lStdinLen );
    lLen = GetStdin( pszStdin, lStdinLen );
    
	unsigned long long int lSummary = 0;
	unsigned long long int lTemp = 0;

	if( lLen > 0 )
	{

	    pszToken = strtok( pszStdin, " " );

	    while ( pszToken != NULL ) 
	    {
			lTemp = strtoull( pszToken, 0, 10 );
			//lTemp = strtoul( pszToken, 0, 10 );
			lSummary += lTemp;

			lNum++;
//	        pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
		    pszToken = strtok( NULL, " " );
	    }

	}

	free( pszStdin );

    return lSummary;
}



int main(int argc, char *argv[]) 
{

    char szCount[10];
    char* pszStdin = 0;
	//char szStdin[50000];
	int lStdinLen = 0;

	int lNum = GetStdin( szCount, 10 );

	int lCount = 0;
	if( lNum >= 1 )
	{
		lCount = atoi( szCount );
	}


	unsigned long long int lSummary = 0;
	lSummary = split( lCount );

	printf( "%lld\n", lSummary );

	//ちなみに long long int 型を printf や scanf で用いる場合に使用する型指定の記号は 'll' を用います。例えば、"value=%lld" という風に書きます。
	return 0;

}

0