fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. string str;
  17. cin >> str;
  18.  
  19. int n = str.size();
  20.  
  21. if(n < 26){
  22. cout << -1;
  23. return;
  24. }
  25.  
  26. bool ok = false;
  27. int idx = -1;
  28.  
  29. for(int i = 0; i + 26 <= n; i++){
  30. map<char,int> freq;
  31. int qcnt = 0;
  32. bool check = true;
  33.  
  34. for(int j = i; j < i + 26; j++){
  35. if(str[j] != '?'){
  36. freq[str[j]]++;
  37. if(freq[str[j]] > 1){
  38. check = false;
  39. break;
  40. }
  41. }
  42. else qcnt++;
  43. }
  44.  
  45. if(check && (int)freq.size() + qcnt == 26){
  46. ok = true;
  47. idx = i;
  48. break;
  49. }
  50. }
  51.  
  52. if(!ok){
  53. cout << -1;
  54. return;
  55. }
  56.  
  57. string res = str.substr(idx, 26);
  58. int fr[26] = {0};
  59. for(char c : res){
  60. if(c != '?')
  61. fr[c - 'A']++;
  62. }
  63.  
  64. vector<char> remain;
  65. for(int k = 0; k < 26; k++){
  66. if(fr[k] == 0)
  67. remain.push_back(char('A' + k));
  68. }
  69.  
  70. int it = 0;
  71. for(char &c : res){
  72. if(c == '?')
  73. c = remain[it++];
  74. }
  75.  
  76. for(int j = 0; j < 26; j++){
  77. str[idx + j] = res[j];
  78. }
  79.  
  80. for(char &c : str){
  81. if(c == '?') c = 'A';
  82. }
  83.  
  84. cout << str;
  85. }
  86.  
  87.  
  88. signed main(){
  89. FastIO();
  90.  
  91. int t = 1;
  92. //cin >> t;
  93.  
  94. while (t--){
  95. solve();
  96. }
  97. return 0;
  98. }
  99.  
Success #stdin #stdout 0s 5308KB
stdin
??????????????????????????
stdout
ABCDEFGHIJKLMNOPQRSTUVWXYZ