fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. short Lwidth, Lheight;
  9. cin >> Lwidth >> Lheight; cin.ignore();
  10. string Text;
  11. char **alphabet = new char*[256];
  12.  
  13. //initializing alphabet
  14. for (char ltr = 'a'; ltr < 'z'+1; ++ltr)
  15. {
  16. alphabet[ltr] = new char[Lwidth];
  17. }
  18. for (char ltr = 'A'; ltr < 'Z'+1; ++ltr)
  19. {
  20. alphabet[ltr] = new char[Lwidth];
  21. }
  22. alphabet['?'] = new char[Lwidth];
  23.  
  24. getline(cin, Text);
  25. for (short h = 0; h < Lheight; ++h)
  26. {
  27. char ltr;
  28. for (ltr = 'a'; ltr < 'z'+1; ++ltr) //reading letters
  29. {
  30. for (short w = 0; w < Lwidth; ++w)
  31. {
  32. scanf("%c", &alphabet[ltr][w]);
  33. alphabet[ltr-('a'-'A')][w] = alphabet[ltr][w];
  34. }
  35. }
  36.  
  37. for (short w = 0; w < Lwidth; ++w) //reading ?
  38. {
  39. scanf("%c", &alphabet['?'][w]);
  40. }
  41.  
  42. scanf("%c", &ltr); //reading endl
  43. if (ltr != '\n') cerr << "ERROR: INVALID TESTS PROVIDED\n";
  44.  
  45. //Putting result out.
  46. for (short i = 0; i < Text.size(); ++i)
  47. {
  48. if //it is a letter
  49. (
  50. (('a'-1 < Text[i]) && (Text[i] < 'z'+1)) ||
  51. (('A'-1 < Text[i]) && (Text[i] < 'Z'+1))
  52. ) //then print it
  53. cout << alphabet[Text[i]];
  54. else //it is definitely something weird
  55. cout << alphabet['?'];
  56. }
  57. cout << '\n';
  58. }
  59. }
Success #stdin #stdout #stderr 0s 15240KB
stdin
1
1
Encoding using ASCII? Hah!
?ZYXWVUTSRQPONMLKJIHGFEDCBA
stdout
WNYMXSNUAGISNUA?IYSSAAT?TA
stderr
ERROR: INVALID TESTS PROVIDED