Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <ctime>
- #include <string>
- using namespace std;
- int columnsQuantity = 0;
- int rowsQuantity = 0;
- char countedCharsTable[100][100];
- char charsTable[100][100];
- string text = string("");
- int charTypesCount = 1;
- char * charTypes = new char[text.size()];
- int count(int c, int r, char t) {
- int n = 0;
- if(charsTable[r][c] != t || countedCharsTable[r][c] == t) {
- return n;
- } else {
- n++;
- countedCharsTable[r][c] = t;
- if(c < columnsQuantity - 1) {
- n += count(c + 1, r, t);
- }
- if(c > 0) {
- n += count(c - 1, r, t);
- }
- if(r < rowsQuantity - 1) {
- n += count(c, r + 1, t);
- }
- if(r > 0) {
- n += count(c, r - 1, t);
- }
- return n;
- }
- }
- int main()
- {
- srand(time( NULL ));
- int * table = new int[10];
- for(int i = 0; i < 10; i++) {
- table[i] = rand() % 10;
- }
- for(int i = 0; i < 10; i++) {
- cout << table[i] << "; ";
- }
- text += "#################aa##a###c######\n";
- text += "####bbbbaaaabbbbbaaaaa###ccc##cc\n";
- text += "#o##bbbbaaaabbbbbaaaaa###c#c##cc\n";
- text += "#oo#bbbbaeeabbbbbbbbaa##cc#ccccc\n";
- text += "#o##bbbbaeeabbbbbaaaaaa#cc#####c\n";
- text += "#o##bbbbaaaabbbbbaaaaaa#cc#####c\n";
- for(int i = 0; i < text.size(); i++) {
- if(text[i] == '\n') {
- rowsQuantity++;
- } else if (rowsQuantity < 1) {
- columnsQuantity++;
- }
- }
- cout << "2D string dimensions: " << rowsQuantity << " rows; " << columnsQuantity << " columns.\n\n";
- int columnIndex = 0;
- int rowIndex = 0;
- for(int i = 0; i < text.size(); i++) {
- if(text[i] != '\n') {
- charsTable[rowIndex][columnIndex] = text[i];
- countedCharsTable[rowIndex][columnIndex] = '-';
- columnIndex++;
- } else {
- rowIndex++;
- columnIndex = 0;
- }
- }
- for(int i = 0; i < rowsQuantity; i++) {
- for(int j = 0; j < columnsQuantity; j++) {
- cout << charsTable[i][j];
- }
- cout << "\n";
- }
- cout << "\n";
- charTypes[0] = text[0];
- for(int i = 0; i < text.size(); i++) {
- if(text[i] != '\n') {
- for(int j = 0; j < charTypesCount; j++) {
- if(charTypes[j] == text[i]) {
- break;
- } else if(j == charTypesCount - 1) {
- charTypes[charTypesCount] = text[i];
- charTypesCount++;
- }
- }
- }
- }
- cout << "Char types: ";
- for(int i = 0; i < charTypesCount; i++) {
- cout << charTypes[i];
- }
- cout << "\n\n";
- int n = 0, r = 0, c = 0;
- char t = charsTable[r][c];
- n = count(r, c, t);
- cout << "\n\nRegion of symbols " << t << ", area: " << n << "\n\n";
- for(int i = 0; i < rowsQuantity; i++) {
- for(int j = 0; j < columnsQuantity; j++) {
- cout << countedCharsTable[i][j];
- }
- cout << "\n";
- }
- cout << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement