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. bool sw = false;
  41. size_t pos = 0;
  42. for (int i = 0; i < N; i++) {
  43. if (EncloseWithBrackets(ShortCut, Options[i], 0)) {
  44. continue;
  45. }
  46. while ((pos = Options[i].find(" ", pos)) != string::npos) {
  47. pos += 1;
  48. if (sw = EncloseWithBrackets(ShortCut, Options[i], pos)) {
  49. break;
  50. }
  51. }
  52. if (sw) {
  53. sw = false;
  54. continue;
  55. }
  56. pos = 0;
  57. while (Options[i][pos] != '\0') {
  58. pos += 1;
  59. if (EncloseWithBrackets(ShortCut, Options[i], pos)) {
  60. break;
  61. }
  62. }
  63. }
  64.  
  65. for (int i = 0; i < N; i++) {
  66. cout << Options[i] << endl;
  67. }
  68. return 0;
  69. }
Success #stdin #stdout 0.01s 5304KB
stdin
5
New
Open
Save
Save As
Save All
stdout
[N]ew
[O]pen
[S]ave
Save [A]s
Sa[v]e All