Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int COL=4,RIG=4;
- const string A[][COL]={{"xioux","aei","aei","aei"},
- {"iou","aei","iou","iou"},
- {"iou","aei","iou","iou"},
- {"aei","iou","aei","aei"}};
- bool contenuto (const string A[][COL], const int RIG, string str);
- bool stringa_trovata(string a,string b);
- int main()
- {
- string str="iou";
- cout << "Verifico che str e' contenuto per almeno il 50% in una matrice A." << endl;
- cout << "Se il risultato e' 1 allora significa che e' vero :" << contenuto(A,RIG,str);
- return 0;
- }
- bool stringa_trovata(string a,string b)
- { // stiamo cercando 'b' in 'a' e non viceversa
- unsigned int n=0,lun_a=a.length(),lun_b=b.length();
- if (lun_a>=lun_b)
- while (n<=lun_a-lun_b)
- {
- if (a.substr(n,lun_b)==b) return true;
- else n++;
- }
- return false;
- }
- bool contenuto (const string A[][COL], const int RIG, string str)
- {
- int i=0, k, contatore=0, meta=RIG*COL/2;
- while (i<RIG)
- {
- k=0;
- while (k<COL)
- {
- if (stringa_trovata(A[i][k],str)) contatore++;
- k++;
- }
- i++;
- }
- if (contatore>=meta) return true;
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement