fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. bool EncloseWithBrackets(string& ReferenceStr, string& TargetStr, size_t pos) {
  9. if (!count(ReferenceStr.begin(), ReferenceStr.end(), TargetStr[pos])) {
  10. if ('A' <= TargetStr[pos] && TargetStr[pos] <= 'Z') {
  11. ReferenceStr += TargetStr[pos];
  12. ReferenceStr += (TargetStr[pos] + 32);
  13. }
  14. if ('a' <= TargetStr[pos] && TargetStr[pos] <= 'z') {
  15. ReferenceStr += TargetStr[pos];
  16. ReferenceStr += (TargetStr[pos] - 32);
  17. }
  18. TargetStr.insert(pos, "[");
  19. TargetStr.insert(pos + 2, "]");
  20. return true;
  21. }
  22. return false;
  23. }
  24.  
  25.  
  26. int main() {
  27. int N = 0;
  28. vector<string> Options;
  29. string ShortCut;
  30.  
  31. cin >> N;
  32.  
  33. cin.ignore();
  34. for (int i = 0; i < N; i++) {
  35. string input;
  36. getline(cin, input);
  37. Options.push_back(input);
  38. }
  39.  
  40. for (int i = 0; i < N; i++) {
  41. cout << Options[i] << endl;
  42. }
  43.  
  44. bool sw = false;
  45. size_t pos = 0;
  46. for (int i = 0; i < N; i++) {
  47. if (EncloseWithBrackets(ShortCut, Options[i], 0)) {
  48. cout << Options[i] << endl;
  49. continue;
  50. }
  51. while ((pos = Options[i].find(" ", pos)) != string::npos) {
  52. pos += 1;
  53. if (sw = EncloseWithBrackets(ShortCut, Options[i], pos)) {
  54. break;
  55. }
  56. }
  57. if (sw) {
  58. sw = false;
  59. cout << Options[i] << endl;
  60. continue;
  61. }
  62. pos = 0;
  63. while (Options[i][pos] != '\0') {
  64. pos += 1;
  65. if (EncloseWithBrackets(ShortCut, Options[i], pos)) {
  66. break;
  67. }
  68. }
  69. cout << Options[i] << endl;
  70. }
  71.  
  72. for (int i = 0; i < N; i++) {
  73. cout << Options[i] << endl;
  74. }
  75. return 0;
  76. }
Success #stdin #stdout 0.01s 5300KB
stdin
5
New
Open
Save
Save As
Save All
stdout
New
Open
Save
Save As
Save All
[N]ew
[O]pen
[S]ave
Save [A]s
Sa[v]e All
[N]ew
[O]pen
[S]ave
Save [A]s
Sa[v]e All