結果

問題 No.193 筒の数式
ユーザー 4885rhkA4885rhkA
提出日時 2015-07-11 20:58:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,823 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 54,976 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 11:16:55
合計ジャッジ時間 1,226 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int popStack()’:
main.cpp:26:40: warning: passing NULL to non-pointer argument 2 of ‘void* memset(void*, int, size_t)’ [-Wconversion-null]
     memset( temp , NULL , sizeof(temp) );
                                        ^

ソースコード

diff #

//
//  main.cpp
//  Q461
//
//  Created by AkihiroKOBAYASHI on 7/11/15.
//  Copyright (c) 2015 Akhr5884. All rights reserved.
//

#include <cstdlib>
#include <iostream>
#include <string>
#include <typeinfo>
#include <string.h>

char temp[20];
int head = 0;

void pushStack(char moji) {
    temp[head] = moji;
    head++;
}

int popStack() {
    std::string stack;
    stack = temp;
    memset( temp , NULL , sizeof(temp) );
    head = 0;
    return std::stoi(stack);
}

int main(int argc, const char * argv[]) {
    
    char moji[40];
    char fugou = '+';
    std::string formula;
    int f_length, i, j, value, maxvalue;
    value = 0;
    maxvalue = -99999999;
    
    std::cin >> formula;
    f_length = (int)formula.length();
    formula = formula + formula;
    sprintf(moji, "%s", formula.c_str());
    
    for(i = 0; i < f_length; i++) {
        if(std::isdigit(static_cast<unsigned char>(moji[i])) && std::isdigit(static_cast<unsigned char>(moji[i+f_length-1]))) {
            for(j = i; j < i + f_length; j++) {
                if(moji[j] == '+' || moji[j] == '-'){
                    if(fugou == '+') {
                        value += popStack();
                    }
                    else if(fugou == '-') {
                        value -= popStack();
                    }
                    fugou = moji[j];
                }
                else {
                    pushStack(moji[j]);
                }
            }
            if(fugou == '+') {
                value += popStack();
            }
            else if(fugou == '-') {
                value -= popStack();
            }
            if(value > maxvalue) {
                maxvalue = value;
            }
            value = 0;
            fugou = '+';
        }
    }
    
    std::cout << maxvalue << '\n';
    
    return 0;
}
0