/ Vijos / 讨论 / 数学 /

计算器

#include<cstdio>
#include<cmath>
#include<cstdlib>
int pailie(double,double);
int j(double);
double mi(double,double);
int y(double,double);
int bei(double a,double c)
{
    return (int)a*(int)c/y((double)a,(double)c);
}
int main()
{
    const double PI=3.141592653589793;
    double a,c,d[105];
    char b;
    printf("有+、-、*、/、@(排列)、=(比较)、g(平方根)、k(KO(只能大K小))、!(阶乘)、f(几次方)、y(最小公倍数)、b(最大公约数)、i(整除&&求余)、,(交换)、?(粗暴合起来)十五种运算符!并且,输入:a“P”b就可以查看 pai 值!(任何运算符皆需2个参数)\n");
    do
    {
        scanf("%lf%c%lf",&a,&b,&c);
        switch(b)
        {
            case '+':printf("%lf",a+c);break;
            case '-':printf("%lf",a-c);break;
            case '*':printf("%lf",a*c);break;
            case '/':if(c){printf("%lf",a/c);break;
            }else{printf("KO!");break;
            }
            case '@':printf("%d",pailie(a,c));break;
            case '=':if(a==c){
                printf("=");
                break;
            }if(a>c){printf(">");break;
            }
            if(a<c){printf("<");break;
            }
            case 'g':printf("%lf",sqrt(a));break;
            case 'k':if(a>c){printf("拜拜!\n");system("pause");return 0;}
              else{
              printf("K不动!");break;}
            case '!':printf("%d",j(a));break;
            case 'f':printf("%lf",mi(a,c));break;
            case 'y':if(c){printf("%d",y(a,c));
                break;
            }else{printf("KO!");break;
            }
            case 'b':if(c){printf("%d",bei(a,c));
                break;
            }else{printf("KO!");break;
            }
            case 'i':if(c){printf("%d......%d",(int)a/(int)c,(int)a%(int)c);
                break;
            }else{printf("KO!");break;
            }
            case ',':printf("%11.3lf     %lf",c,a);break;
            case '?':printf("%.2lf%.3lf",a,c);break;
            case 'P':printf("%.15lf23846264",PI);break;
            default:printf("your KO!");
        }
        printf("\n");(double)a;
    }
    while(1);
 }
 int pailie(double a,double b)
 {
    int s=1;
    for(int i=(int)a;i>(int)a-(int)b;i--)
      s*=i;
    return s;
  } 
int j(double a)
{
    int s=1;
    for(int i=1;i<=(int)a;i++)
      s*=i;
    return s;
}
double mi(double n,double m)
{
    int s=1;
    for(int i=1;i<=m;i++)
      s*=n;
    return s;
}
int y(double a,double b)
{
    int c=(int)a%(int)b;
    while(c)
    {
        a=b;b=c;c=(int)a%(int)b;
    }
    return b;
}
//出金点子的格式:“金点子”姓名“(”符号种类“) 
//金点子: 

停!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

\(\huge\color{Red}\texttt{我不太会}\)

2 条评论

  • @ 2019-08-27 10:14:51

    个人觉得不是很好,还不如python中eval直接可以秒杀着95行代码。并且这个只能计算1个符号的中缀表达式,没有用单调栈来计算一整个。

  • @ 2019-08-24 16:01:04

    看清说明哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦!!!!!!!!!!!!!!!!!!!!!!

    • @ 2019-10-29 09:05:54

      看清说明哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦哦啊哦!!!!!!!!!!!!!!

  • 1