結果

問題 No.49 算数の宿題
ユーザー goodbaton
提出日時 2014-11-20 23:38:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 702 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 64,660 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-23 01:42:57
合計ジャッジ時間 1,069 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:17:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |     scanf("%s",s);
      |     ~~~~~^~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>

using namespace std;

int main(){
    char s[110],en='*';
    int ans=0,nu=0;
    
    scanf("%s",s);
    
    for(int i=0;s[i]!='\0';i++){
        if(s[i]=='+' || s[i]=='*'){
            if(en=='*')
                ans+=nu;
            else
                ans*=nu;
            en=s[i];
            nu=0;
        }else{
            nu*=10;
            nu+=s[i]-'0';
        }
    }
    
    if(en=='*')
        ans+=nu;
    else
        ans*=nu;
    
    printf("%d\n",ans);
    
    return 0;
}
0