結果

問題 No.222 引き算と足し算
ユーザー alpha_virginis
提出日時 2015-06-13 16:54:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 962 bytes
コンパイル時間 1,221 ms
コンパイル使用メモリ 159,748 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-15 21:54:53
合計ジャッジ時間 2,132 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int main() {

  std::string str;
  int temp;
  int flag;
  int p;
  int n1, n2;
  char ope;

  std::cin >> str;

  p = 0;
  
  temp = 0;
  flag = 1;
  if( not ( '0' <= str[p] and str[p] <= '9' ) ) {
    if( str[p] == '-' ) {
      flag = -1;
    }
    p += 1;
  }
  for(p = p; p < str.size(); ++p) {
    if( '0' <= str[p] and str[p] <= '9' ) {
      temp *= 10;
      temp += str[p] - '0';
    }
    else {
      break;
    }
  }
  n1 = temp * flag;

  ope = str[p];
  p += 1;


  temp = 0;
  flag = 1;
  if( not ( '0' <= str[p] and str[p] <= '9' ) ) {
    if( str[p] == '-' ) {
      flag = -1;
    }
    p += 1;
  }
  for(p = p; p < str.size(); ++p) {
    if( '0' <= str[p] and str[p] <= '9' ) {
      temp *= 10;
      temp += str[p] - '0';
    }
    else {
      break;
    }
  }
  n2 = temp * flag;

  if( ope == '+' ) {
    std::cout << n1 - n2 << std::endl;
  }
  else {
    std::cout << n1 + n2 << std::endl;
  }

  return 0;
}
0