导致RE的代码片段,初步猜测是 stio 函数的问题:
//判断前导零
for(int i = 1;i <= 4;i ++)
if(to_string((int)stoi(qwq[i])) != qwq[i]){
cout<<"ERR"<<endl;
goto kill;
}
//判断范围
for(int i = 1;i <= 4;i ++)
if(stoi(qwq[i]) < 0 || stoi(qwq[i]) > 255){
cout<<"ERR"<<endl;
goto kill;
}
if(stoi(qwq[5]) < 0 || stoi(qwq[5]) > 65535){
cout<<"ERR"<<endl;
完整代码:
#include<bits/stdc++.h>
using namespace std;
unordered_map<string,int> um;
string op,ad;
int n;
int main(){
cin>>n;
for(int q = 1;q <= n;q ++){
if(114514 == 1919810){
kill:continue;
}
cin>>op>>ad;
//判断格式
string k;
for(int i = 0;i < ad.size();i ++)
if(ad[i] == '.' || ad[i] == ':')
k.push_back(ad[i]);
if(k != "...:"){
cout<<"ERR"<<endl;
goto kill;
}
//截取字符串
string find[] = {"艹什么毒瘤题目",".",".",".",":"},qwq[10];
k = ad;
for(int i = 1;i <= 4;i ++)
for(int j = 0;j < k.size();j ++)
if(k[j] == find[i][0]){
qwq[i] = k.substr(0,j);
k.erase(0,j + 1);
break;
}
qwq[5] = k;
for(int i = 1;i <= 5;i ++)
if(!qwq[i].size()){
cout<<"ERR"<<endl;
goto kill;
}
//判断前导零
for(int i = 1;i <= 4;i ++)
if(to_string((int)stoi(qwq[i])) != qwq[i]){
cout<<"ERR"<<endl;
goto kill;
}
//判断范围
for(int i = 1;i <= 4;i ++)
if(stoi(qwq[i]) < 0 || stoi(qwq[i]) > 255){
cout<<"ERR"<<endl;
goto kill;
}
if(stoi(qwq[5]) < 0 || stoi(qwq[5]) > 65535){
cout<<"ERR"<<endl;
goto kill;
}
//连接
if(op[0] == 'S'){
if(!um[ad]){
um[ad] = q;
cout<<"OK"<<endl;
}
else cout<<"FAIL"<<endl;
}
else {
if(um[ad])
cout<<um[ad]<<endl;
else cout<<"FAIL"<<endl;
}
}
return 0;
}
希望有大佬帮我这个可怜的蒟蒻吧