Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- vector<std::vector<char>> readInput(const int& matrixSize)
- {
- vector<std::vector<char>> matrix {};
- char symbol = '_';
- for (int row = 0; row < matrixSize; ++row)
- {
- vector<char> rowSymbols {};
- for (int col = 0; col < matrixSize; ++col)
- {
- cin >> symbol;
- rowSymbols.push_back(symbol);
- }
- matrix.push_back(rowSymbols);
- }
- return matrix;
- }
- bool findSearchedElement(const std::vector<std::vector<char>>& matrix, const char& findEelement, int& rowIndex, int& colIndex)
- {
- bool isFound = false;
- for (int i = 0; i < matrix.size(); ++i)
- {
- for (int j = 0; j < matrix[i].size(); ++j)
- {
- if(matrix[i][j] == findEelement)
- {
- isFound = true;
- rowIndex = i;
- colIndex = j;
- break;
- }
- }
- if(isFound){
- break;
- }
- }
- return isFound;
- }
- void printResult(const bool& isFound, const char& searchedElement, const int& rowIndex, const int& colIndex)
- {
- if(isFound)
- {
- cout << "(" << rowIndex << ", " << colIndex << ")" << endl;
- }
- else {
- cout << searchedElement << " does not occur in the matrix " << endl;
- }
- }
- int main()
- {
- int matrixSize = 0;
- cin >> matrixSize;
- vector<std::vector<char>> matrix = readInput(matrixSize);
- char searchedElement = '_';
- cin >> searchedElement;
- int rowIndex = 0;
- int colIndex = 0;
- bool isFound = findSearchedElement(matrix, searchedElement, rowIndex, colIndex);
- printResult(isFound, searchedElement, rowIndex, colIndex);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement