你或许需要使用 stoll 而不是 stoi,例如
stoll
stoi
while (!v[s]) { v[s] = ans.size() + 1; ans.push_back(s); string Min = s, Max = s; sort (Min.begin(), Min.end()); sort (Max.begin(), Max.end(), greater<char>()); s = to_string(stoll(Max) - stoll(Min)); }