fork download
  1. /*
  2. Name : Mohit Khare
  3. B.Tech 2nd Year
  4. Computer Science and Engineering
  5. MNNIT Allahabad
  6. */
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. #define F(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
  10. #define RF(i,a,b) for(int i = (int)(a); i > (int)(b); i--)
  11. #define ll long long int
  12. #define ull unsigned long long int
  13. #define pii pair < int , int >
  14. #define pb push_back
  15. #define mp make_pair
  16. #define mod 1000000007
  17. int main()
  18. {
  19. //freopen("input.txt","r",stdin);
  20. //freopen("output.txt","w",stdout);
  21. char ch[500000],st[26],ans[26];
  22. cin>>ch;
  23. int hash[26],cnt=0,q=0,f=0,m=0,p=0;
  24. int len = strlen(ch),i;
  25. if(len<26)
  26. {
  27. cout<<"-1"<<endl;
  28. return 0;
  29. }
  30. for( i = 0;i<=len-26;i++)
  31. {
  32. for(int j = 0;j<26 ; j++)
  33. {
  34. if(ch[i+j]!='?')
  35. hash[ch[i+j]-'A']++;
  36. else q++;
  37. }
  38. for(int k = 0 ;k<26;k++)
  39. {
  40. if(hash[k]==0)
  41. {
  42. cnt++;
  43. st[m]=(char)('A'+k);
  44. m++;
  45. }
  46. }
  47. m=0;
  48. if(cnt<=q)
  49. {
  50. f=1;
  51. for(int k= 0;k<26;k++)
  52. {
  53. if(ch[i+k]=='?')
  54. {
  55. ans[p]=st[m];
  56. p++;
  57. m++;
  58. }
  59. else
  60. {
  61. ans[p]=ch[i+k];
  62. p++;
  63. }
  64. }
  65. break;
  66. }
  67. cnt =0;
  68. q=0;
  69. m=0;
  70. memset(hash,0,sizeof(hash));
  71. char st[26];
  72. }
  73. if(f)
  74. {
  75. for(m =0;m<i;m++)
  76. if(ch[m]=='?')
  77. cout<<"A";
  78. else cout<<ch[m];
  79. cout<<ans;
  80. for( m=26+i;m<len;m++)
  81. {
  82. if(ch[m]=='?')
  83. cout<<"A";
  84. else cout<<ch[m];
  85. }
  86. }
  87. else cout<<-1<<endl;
  88. return 0;
  89. }
Success #stdin #stdout 0s 3836KB
stdin
ABC??FGHIJK???OPQR?TUVWXY?
stdout
ABCDEFGHIJKLMNOPQRSTUVWXYZ