选几个值带进去算一下就可以了=-=
不想写了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
// <equal.cpp> - 03/06/16 14:40:52 // This file is created by XuYike's black technology automatically. // Copyright (C) 2015 ChangJun High School, Inc. // I don't know what this program is. #include <iostream> #include <vector> #include <algorithm> #include <cstring> #include <cstdio> #include <cmath> using namespace std; typedef long long lol; int getint(){ int res=0,fh=1;char ch=getchar(); while((ch>'9'||ch<'0')&&ch!='-')ch=getchar(); if(ch=='-')fh=-1,ch=getchar(); while(ch>='0'&&ch<='9')res=res*10+ch-'0',ch=getchar(); return fh*res; } lol check,result_t; lol num[50],op[50]; lol power(lol a,lol b){ lol k=1; for(int i=0;i<b;i++)k*=a; return k; } void cul(int p,int op){ if(op==0)num[p-1]=num[p-1]+num[p]; if(op==1)num[p-1]=num[p-1]-num[p]; if(op==2)num[p-1]=num[p-1]*num[p]; if(op==5)num[p-1]=power(num[p-1],num[p]); } lol result(string str){ int op_nxt,len=str.length(),p=-1,q=-1; lol num_nxt=0; for(int i=0;i<len;i++){ if(str[i]=='a')num[++p]=check; else if(str[i]>='0'&&str[i]<='9')num_nxt=num_nxt*10+(str[i]-'0'); else if(str[i]!=' '){ if(num_nxt!=0){ num[++p]=num_nxt; num_nxt=0; } if(str[i]=='+')op_nxt=0; if(str[i]=='-')op_nxt=1; if(str[i]=='*')op_nxt=2; if(str[i]=='^')op_nxt=5; if(str[i]=='(')op_nxt=6; if(str[i]==')')op_nxt=7; if(op_nxt==6)op[++q]=op_nxt; else if(op_nxt==7) while(q>=0&&op[q--]!=6)cul(p--,op[q+1]); else{ while(q>=0&&op[q]<=5&&op[q]/2>=op_nxt/2)cul(p--,op[q--]); op[++q]=op_nxt; } } } if(num_nxt){ num[++p]=num_nxt; num_nxt=0; } while(q>=0)cul(p--,op[q--]); return num[0]; } int main(){ freopen("equal.in","r",stdin); freopen("equal.out","w",stdout); string str1,str2; getline(cin,str1); int n=getint(); for(int i=0;i<n;i++){ bool flag=1; getline(cin,str2); for(int i=10;i<=20;i++){ check=i; if(result(str1)!=result(str2)){flag=0;break;} } if(flag)cout<<(char)('A'+i); } return 0; } |