41分求解qwq
查看原帖
41分求解qwq
288716
lzqy_楼主2020/6/2 20:26
#include<bits/stdc++.h>
using namespace std;
char c;
inline double read()                        //以字符串形式读入数字可提速
{
  int x=0;
  c='k';
  c=getchar();
  for(; c<'0'  || c>'9';  c=getchar())
    if(c=='?')
      return -1;
  for(; c<='9' && c>='0'; c=getchar())
    x=(x<<3)+(x<<1)+c-'0';               //位运算优化即x*8+x*2=x*10
  return double(x);
}
int main()
{
  double a,b,C;
  char x;
  a=read();
  x=c;
  b=read();
  C=read();
  if(x=='+')
  {
    if(C==-1)
      cout<<setprecision(2)<<fixed<<a+b;
    else if(a==-1)
      cout<<setprecision(2)<<fixed<<C-b;
    else
      cout<<setprecision(2)<<fixed<<C-a;
  }
  if(x=='-')
  {
    if(C==-1)
      cout<<setprecision(2)<<fixed<<a-b;
    else if(a==-1)
      cout<<setprecision(2)<<fixed<<C+b;
    else
      cout<<setprecision(2)<<fixed<<a-C;
  }
  if(x=='*')
  {
    if(C==-1)
      cout<<setprecision(2)<<fixed<<a*b;
    else if(a==-1)
      cout<<setprecision(2)<<fixed<<C/b;
    else
      cout<<setprecision(2)<<fixed<<C/a;
  }
  if(x=='/')
  {
    if(C==-1)
      cout<<setprecision(2)<<fixed<<a/b;
    else if(a==-1)
      cout<<setprecision(2)<<fixed<<C*b;
    else
      cout<<setprecision(2)<<fixed<<a/C;
  }
  return 0;
}

就是用快读的形式过滤空格,然后依次判断符号来计算

2020/6/2 20:26
加载中...