fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <algorithm>
  5. #include <bits/stdc++.h>
  6. #include <set>
  7. #include <ext/pb_ds/assoc_container.hpp>
  8. #include <ext/pb_ds/tree_policy.hpp>
  9. #include <map>
  10. #define ll long long
  11. using namespace __gnu_pbds;
  12. using namespace std;
  13. template <class T>
  14. using ordered_set = tree<T , null_type , less<T> , rb_tree_tag , tree_order_statistics_node_update>;
  15. template <class T>
  16. using ordered_set1 = tree<T , null_type , greater<T> , rb_tree_tag , tree_order_statistics_node_update>;
  17. // less<T>/greater<T> = ascending/descending.
  18. // less_equal<>/greater_equal<> for ordered multiset
  19. // ordered_multiset note : s.find(), s.erase() don't work + s.upper_bound() and s.lower_bound() swap jobs;
  20. void fastIO(void) {
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(NULL);
  23. cout.tie(NULL);
  24. }
  25.  
  26. int main() {
  27. fastIO();
  28. string s; cin>>s;
  29. ll l = 0, r=l;
  30. int freq[26]={0};
  31. while (r<s.size() && r-l<=25) {
  32. while (r<s.size() && s[r]=='?' && r-l<=25) {
  33. r++;
  34. }
  35. freq[s[r]-'A']++;
  36. while (freq[s[r]-'A']>1) {
  37. if (s[l]!='?') {
  38. freq[s[l]-'A']--;
  39. }
  40. l++;
  41. }
  42. r++;
  43. }
  44. string sub = s.substr(l,26);
  45. if (r>l+25) {
  46. for (ll i = 0; i<sub.size(); i++) {
  47. if (sub[i]=='?') {
  48. for (ll j = 0; j<26; j++) {
  49. if (freq[j]==0) {
  50. freq[j]++;
  51. sub[i]='A'+j;
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. cout<<sub;
  58. }
  59. else {
  60. cout<<-1;
  61. }
  62. }
Success #stdin #stdout 0s 5316KB
stdin
ABC??FGHIJK???OPQR?TUVWXY?
stdout
ABCDEFGHIJKLMNOPQRSTUVWXYZ