答案一定要比数字的每一位大
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
char s[100];
int main()
{
while(scanf("%s",s+1)!=EOF)
{
int flag=0;
int len=strlen(s+1);
int maxx=2;
for(int i=1;i<=len;i++)
{
if(s[i]>='0'&&s[i]<='9')
{
maxx=max(maxx,s[i]-'0'+1);
}
else if(s[i]>='A'&&s[i]<='F')
{
maxx=max(maxx,s[i]-'A'+11);
}
}
for(int i=16;i>=maxx;i--)
{
ll num1=0,num2=0,num3=0;
int c=1;
while(s[c]>='0'&&s[c]<='9'||s[c]>='A'&&s[c]<='F')
{
if(s[c]>='0'&&s[c]<='9')
num1=num1*i+(s[c]-'0');
else
num1=num1*i+(s[c]-'A'+10);
c++;
}
char op=s[c];
c++;
while(s[c]>='0'&&s[c]<='9'||s[c]>='A'&&s[c]<='F')
{
if(s[c]>='0'&&s[c]<='9')
num2=num2*i+(s[c]-'0');
else
num2=num2*i+(s[c]-'A'+10);
c++;
}
c++;
while(s[c]>='0'&&s[c]<='9'||s[c]>='A'&&s[c]<='F')
{
if(s[c]>='0'&&s[c]<='9')
num3=num3*i+(s[c]-'0');
else
num3=num3*i+(s[c]-'A'+10);
c++;
}
if(op=='+')
{
if(num1+num2==num3)
{
flag=i;
}
}
else if(op=='-')
{
if(num1-num2==num3)
{
flag=i;
}
}
else if(op=='*')
{
if(num1*num2==num3)
{
flag=i;
}
}
else if(op=='/')
{
if(num1/num2==num3&&num1%num2==0)
{
flag=i;
}
}
}
if(flag==0) printf("-1\n");
else printf("%d\n",flag);
}
}