报错:
terminate called after throwing an instance of 'std::out_of_range'
what(): stoi
#include <iostream>
#include <cmath>
#include <cstring>
#include <string>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <sstream>
using namespace std;
int change(int a,int d){
if(a==0){
return 0;
}
int i=0;char s[120];
while(a!=0){
int f=a%d;
if(f<10){
s[i++]=f+'0';
}else{
char v='a'+f-10;
s[i++]=v;
}
a/=d;
}
string k="";
for (int j = i - 1; j >= 0; j--) {
k=k+to_string(s[j]);
}
int iu= stoi(k,0,10);
return iu;
}
int main(){
srand(time(0));
int hard=2;
hard=hard%10;
int p[hard][hard][hard];
for (int i=0;i<hard;i++){
for (int j=0;j<hard;j++){
for (int x=0;x<hard;x++){
p[i][j][x]=0;
}
}
}
int a1=rand()%hard,a2=rand()%hard,a3=rand()%hard;
p[a1][a2][a3]=666;
int truenl=0;
for (int i=0;i<500;i++){
if(change(i,hard)==(hard-1)*111){
truenl=i;
break;
}
}
cout<<"input a num:>=0,<="<<truenl<<endl;
int a789,a78;
cin>>a789;
a78=change(a789,hard);
int a,b,c;
a=a78%10;
a78=a78-a;
a78=a78/10;
b=a78%10;
a78=a78-b;
a78=a78/10;
c=a78%10;
try{
if (a>=hard || b>=hard || c>=hard){
throw 77;
}
if (p[a][b][c]==0){
cout<<"lose"<<endl;
cout<<"right num: "<<change(a1*100+a2*10+a3,hard)<<endl;
}else{
cout<<p[a][b][c]<<endl;
}
}catch(int){
cout<<"wrong:you should input a number that <= "<<truenl<<"!"<<endl;
}
return 0;
}
```