結果
| 問題 |
No.9008 空白区切りで与えられる数値データの合計値を求める(テスト用)
|
| ユーザー |
|
| 提出日時 | 2017-03-26 17:46:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,227 bytes |
| コンパイル時間 | 172 ms |
| コンパイル使用メモリ | 25,472 KB |
| 実行使用メモリ | 12,040 KB |
| 最終ジャッジ日時 | 2024-07-06 06:31:24 |
| 合計ジャッジ時間 | 2,298 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 7 RE * 8 |
ソースコード
#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[]) {
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 )
{
apszOutList[ lNum ] = pszToken;
lNum++;
// pszToken = strtok_s(NULL, pszDelim, &pszNext_token);
pszToken = strtok( NULL, pszDelim );
}
}
return lNum;
}
int main(int argc, char *argv[])
{
char szCount[10];
char* pszStdin = 0;
//char szStdin[50000];
int lStdinLen = 0;
char szDelimit[2] = " ";
char* apszOutList[ 50000 ] = { 0 };
int lNum = GetStdin( szCount, 10 );
int lCount = 0;
if( lNum >= 1 )
{
lCount = atoi( szCount );
}
lStdinLen = lCount * 20 + lCount;
pszStdin = ( char* )malloc( lStdinLen );
lNum = split( pszStdin, lStdinLen, szDelimit, apszOutList );
unsigned long long int lSummary = 0;
unsigned long long int lTemp = 0;
for( int i = 0; i < lCount; i++ )
{
lTemp = strtoull( apszOutList[i], 0, 10 );
//lTemp = strtoul( apszOutList[i], 0, 10 );
lSummary += lTemp;
}
printf( "%lld\n", lSummary );
free( pszStdin );
//ちなみに long long int 型を printf や scanf で用いる場合に使用する型指定の記号は 'll' を用います。例えば、"value=%lld" という風に書きます。
return 0;
}