Advertisement
vencinachev

Diagonal

Dec 15th, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3.  
  4. #define EXAMPLE
  5.  
  6. using namespace std;
  7.  
  8. enum State { START, WORD, SPACE };
  9.  
  10. string acronym(string text);
  11.  
  12. int main()
  13. {
  14. const int MAX = 20;
  15. #ifdef EXAMPLE
  16. int matrix[MAX][MAX] = {{1, 2, 3, 4},
  17. {5, 6 ,7 ,8},
  18. {9,10,11,12},
  19. {13,14,15,16}};
  20. int n = 4;
  21. #else
  22. int matrix[MAX][MAX];
  23. int n;
  24. do
  25. {
  26. cout << "Enter n: ";
  27. cin >> n;
  28. }
  29. while (n < 1 || n > MAX);
  30.  
  31. for (int i = 0; i < n; i++)
  32. {
  33. for (int j = 0; j < n; j++)
  34. {
  35. cin >> matrix[i][j];
  36. }
  37. }
  38. #endif
  39.  
  40. for (int i = 0; i < n; i++)
  41. {
  42. for (int row = i, col = 0; row >= 0 ; row--, col++)
  43. {
  44. cout << matrix[row][col] << " ";
  45. }
  46. cout << endl;
  47. }
  48.  
  49. for (int i = 1; i < n ; i++)
  50. {
  51. for (int col = i, row = n - 1; col < n; row--, col++)
  52. {
  53. cout << matrix[row][col] << " ";
  54. }
  55. cout << endl;
  56. }
  57.  
  58. return 0;
  59. }
  60.  
  61. string acronym(string text)
  62. {
  63. State st = START;
  64. string acr = "";
  65. if (isalpha(text[0]))
  66. {
  67. st = WORD;
  68. acr += toupper(text[0]);
  69. }
  70. else
  71. {
  72. st = SPACE;
  73. }
  74. for (int i = 1; i <= text.length(); i++)
  75. {
  76. if (st == SPACE)
  77. {
  78. if (isalpha(text[i]))
  79. {
  80. st = WORD;
  81. acr += toupper(text[i]);
  82. }
  83. }
  84. else if (st == WORD)
  85. {
  86. if (!isalpha(text[i]))
  87. {
  88. st = SPACE;
  89. }
  90. }
  91. }
  92. return acr;
  93. }
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement