結果

問題 No.388 階段 (1)
ユーザー Sylvanas_ship3Sylvanas_ship3
提出日時 2017-04-03 13:22:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,871 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 69,444 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 11:27:17
合計ジャッジ時間 1,399 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
#include <cmath>

#define DEBUG

int getInputNumber( const std::string& );
std::vector<std::string> split( const std::string&, std::string );

int main()
{
    std::cin.sync_with_stdio( false );
    std::cin.tie( 0 );

    // get input from stdout
    std::string input;
    int current_stage = 0, floor_num_in_home = 0;
    if ( std::getline( std::cin, input ) )
    {
        std::vector<std::string> argv = split( input, " " );
        if ( argv.size() > 1 ) 
        {
            current_stage = getInputNumber(argv[0]);
            floor_num_in_home = getInputNumber(argv[1]);
        }
        else
        {
            return -1;
        }
    }

    int ans = 1;
    ans += std::floor( static_cast<double>( current_stage ) / floor_num_in_home );
    std::cout << ans << std::endl;

    return 0;
}

int getInputNumber( const std::string& input )
{
    int input_number = 0;

    try
    {
        input_number = std::stoi( input );
    }
    catch ( std::invalid_argument& )
    {
        return 0;
    }
    catch ( std::out_of_range& )
    {
        return 0;
    }

    return input_number;
}

std::vector<std::string> split( const std::string& str, std::string delim )
{
    std::vector<std::string> result;
    result.reserve( 8 );

    std::string::size_type pos = 0;
    while ( pos != std::string::npos )
    {
        std::string::size_type current = str.find( delim, pos );
        if ( current == std::string::npos )
        {
            result.push_back( str.substr( pos ) );
            break;
        }
        else
        {
            std::string tmp = str.substr( pos, current - pos );
            if ( !tmp.empty() )
            {
                result.push_back( tmp );
            }
        }

        pos = current + delim.length();
    }

    return result;
}
0