网易互娱模拟第三题通过率为0,但给的测试用例都能过。
网易互娱模拟第三题,给的测试用例能通过,但提交case 0%的通过率,有没有大佬告知错在哪里?
#include<iostream> #include<string> using namespace std; int x,y; string str; int result; bool splitStr(int index){ int res1 = 0; for(int i = 0; i < index; i++){ if(str[i] <= '9'){ res1 = res1 * x + (str[i] - '0'); } else{ res1 = res1 * x + (str[i] - 'A' + 10); } } int res2 = 0; for(int i = index; i < str.size(); i++){ if(str[i] <= '9'){ res2 = res2 * y + (str[i] - '0'); } else{ res2 = res2 * y + (str[i] - 'A' + 10); } } if(res1 == res2){ result = res1; return true; } else return false; } int main(){ int n; cin >> n; for(int k = 0; k < n; k++){ cin >> x >> y >> str; if(x == y){ int res = 0; for(int i = 0; i < str.size()/2; i++){ if(str[i] <= '9'){ res = res * y + (str[i] - '0'); } else{ res = res * y + (str[i] - 'A' + 10); } } cout << res << endl; } else if(x < y){ int i = 0; while(i < str.size() && str[i] - '0' < x){ i++; } for(int j = i; j > 0; j--){ if(splitStr(j) == true){ cout << result <<endl; break; } } } else{ int i = str.size()-1; while(i >= 0 && str[i] - '0' < y){ i--; } i++; for(int j = i; j < str.size()-1; j++){ if(splitStr(j) == true){ cout << result <<endl; break; } } } } return 0; }#网易互娱##笔试题目#