Results 1 to 4 of 4
Thread: C++
Hybrid View
-
8th January 2015 01:32 #1Registered User
Join Date: Jul:2014
Location: Dobrich
Posts: 10
C++
C++, - , , main , , , , . ( , ) : ...\main.cpp|44|error: cannot convert 'std::string (*)[(((sizetype)(((ssizetype)m) + -1)) + 1)] {aka std::basic_string<char> (*)[(((sizetype)(((ssizetype)m) + -1)) + 1)]}' to 'std::string (*)[100] {aka std::basic_string<char> (*)[100]}' for argument '4' to 'bool compareStrings(std::string, int, int, std::string (*)[100])'|.
Code:#include <iostream> #include <string.h> using namespace std; bool compareStrings(string wordToCompare, int n, int m, string arr[100][100]); int main() { //declare n x m matrix int n; int m; do { cout << "Enter n and then m: " <<endl; cin >> n; cin >> m; } while(n <= 3 || n > m || m >= 100); //read t-number for the words to be found int t; cout << "Enter t: " << endl; cin >> t; //initialize matrix string arr[n][m]; cout<<"Initialize matrix: "<<endl; for(int row = 0; row < n; row++) { for(int col = 0; col < m; col++) { cin >> arr[row][col]; } } //Enter t words cout<<"enter words to find" << endl; string wordToCompare; // for(int i = 0; i < t; i++) // { cin >> wordToCompare; bool areEqual = compareStrings(wordToCompare, n, m, arr); // } cout << wordToCompare << " " << areEqual << endl; return 0; } bool compareStrings(string wordToCompare, int n, int m, string arr[100][100]) { //compare string horizontally from left to right TESTED bool areEqual = false; for(int row = 0; row < n; row++) { for(int col = 0; col < m; col++) { string compareString = ""; for(int i = col; i < m; i++) { compareString.append(arr[row][i]); areEqual = !wordToCompare.compare(compareString); if(areEqual) { return true; } } } } //compare string horizontally from right to left TESTED for(int row = 0; row < n; row++) { for(int col = m-1; col >= 0; col--) { string compareString = ""; for(int i = col; i >= 0; i--) { compareString.append(arr[row][i]); areEqual = !wordToCompare.compare(compareString); if(areEqual) { return true; } } } } //compare string vertically from bottom to top TESTED for(int col = 0; col < n; col++) { for(int row = n-1; row >= 0; row--) { string compareString = ""; for(int i = row; i >= 0; i--) { compareString.append(arr[i][col]); areEqual = !wordToCompare.compare(compareString); if(areEqual) { return true; } } } } //compare string vertically from top to bottom TESTED for(int col = 0; col < n; col++) { for(int row = 0; row < n; row++) { string compareString = ""; for(int i = row; i < n; i++) { compareString.append(arr[i][col]); areEqual = !wordToCompare.compare(compareString); if(areEqual) { return true; } } } } return false; }
-
8th January 2015 08:08 #2
100, m. .
bool compareStrings(string wordToCompare, int n, int m, string arr[][100]);
string arr[n][100] arr[n][m]
[n][m] -
Code:string **arr = new string*[n]; for (int i=0; i<n; i++) arr[i]=new string[m];
bool compareStrings(string wordToCompare, int n, int m, string **arr);Last edited by ined; 8th January 2015 at 08:35.
ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173
-
8th January 2015 13:15 #3Registered User
Join Date: Jul:2014
Location: Dobrich
Posts: 10
. . , 1 2 cin.
-
8th January 2015 13:22 #4
- ,Code:for(int row = 0; row < n; row++) { for(int col = 0; col < m; col++) { cin >> arr[row][col]; } }
Code:string **arr = new string*[n]; for(int row = 0; row < n; row++) { arr[row] = new string[m]; for(int col = 0; col < m; col++) { cin >> arr[row][col]; } }ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173




Reply With Quote
Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in