Advertisement
Spocoman

03. Symbol in Matrix

Jan 26th, 2024
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     int n;
  8.     cin >> n;
  9.  
  10.     char el;
  11.  
  12.     vector<vector<int>> matrix;
  13.  
  14.     for (int i = 0; i < n; i++) {
  15.         vector<int> currentRow;
  16.         for (int j = 0; j < n; j++) {
  17.             cin >> el;
  18.             currentRow.push_back(el);
  19.         }
  20.         matrix.push_back(currentRow);
  21.     }
  22.  
  23.     char symbol;
  24.     cin >> symbol;
  25.  
  26.     for (int i = 0; i < n; i++) {
  27.         for (int j = 0; j < n; j++) {
  28.             if (matrix[i][j] == symbol) {
  29.                 printf("(%i, %i)\n", i, j);
  30.                 return 0;
  31.             }
  32.         }
  33.     }
  34.  
  35.     printf("%c does not occur in the matrix\n", symbol);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement