結果

問題 No.193 筒の数式
ユーザー 4885rhkA4885rhkA
提出日時 2015-07-11 19:40:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,794 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 54,912 KB
実行使用メモリ 4,564 KB
最終ジャッジ日時 2023-09-22 11:16:16
合計ジャッジ時間 1,326 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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++) {
        value = 0;
        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] != '-'){
                    pushStack(moji[j]);
                }
                else {
                    if(fugou == '+') {
                        value += popStack();
                    }
                    else if(fugou == '-') {
                        value -= popStack();
                    }
                    fugou = moji[j];
                }
            }
            if(fugou == '+') {
                value += popStack();
            }
            else if(fugou == '-') {
                value -= popStack();
            }
            if(value > maxvalue) {
                maxvalue = value;
            }
        }
    }
    
    std::cout << maxvalue << '\n';
    
    return 0;
}
0