結果

問題 No.49 算数の宿題
ユーザー receive_classesreceive_classes
提出日時 2016-08-24 22:48:04
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,726 bytes
コンパイル時間 547 ms
コンパイル使用メモリ 84,688 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-08-24 17:33:58
合計ジャッジ時間 1,134 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#include "math.h"
#include <complex>
#include <iomanip>
#include <map>
#include <iostream>
#define ifor(i,a,b) for (int i=(a);i<(b);i++)
#define rfor(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define rep(i,n) for (int i=0;i<(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
using namespace std;
typedef long double ld;
typedef long long int  lli;
typedef complex <double> P;
const double eps = 1e-11;
int vex[4]={1,0,-1,0};
int vey[4]={0,1,0,-1};
typedef vector<double> Vec;
typedef vector<int> vec;
typedef vector<Vec> MAT;
typedef vector<vec> mat;
double expr(string& ,int& );
double term(string& ,int& );
double factor(string& ,int& );
double number(string& ,int& );

double expr(string &s ,int &i  ){
  double val = term(s,i);
  while(s[i] =='+'||s[i] =='-'){
    char op = s[i];
    i++;
    double val2 = term(s,i);
    if(op=='+')val += val2;
    else val -= val2;
  }
  return val;
}
double term(string &s,int &i ){
  double val = factor(s,i);
  while(s[i] =='*'||s[i]=='/'){
    char op= s[i];
    i++;
    double val2 = factor(s,i);
    if(op=='*')val *=val2;
    else val /= val2;
  }
  return val;
}
double factor(string &s,int &i){
  if(isdigit(s[i]))return number(s,i);
  i++;
  double ret = expr(s,i);
  i++;
  return ret;
}
double number(string &s,int &i){
  int n = s[i++]-'0';
  double a = 0;
  int order = 1;
  int b=0;
  while(isdigit(s[i]))n=n*10+s[i++]-'0';
  if(s[i]=='.'){
    i++;
    while(isdigit(s[i])){
      b = (double)(s[i++]-'0');
      a += b*pow(0.1,order);
      order++;
    }
  }
  a += (double)n;
  return a;
}
int main(){
  string s;
  int i =0;
  cin >>s;
  cout<<expr(s,i)<<endl;
  return  0;
}
0