Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- string desi2(string x); // restituisce le ultime due lettere di una stringa
- string stringab(string a[],int b); // restituisce b="" se non ci sono corrispondenze
- // oppure i primi 4 car. di 3 string di uguale desinenza
- int main()
- {
- string a[]={"ilmnzz","abcd56","123456","efgh56"};
- cout << "Provo a costruire la stringa 'b' partendo da un array 'a' di 4 stringhe : " << stringab(a,4);
- return 0;
- }
- string desi2(string x)
- {
- string temp;
- temp=x.substr(x.length()-2,2);
- return temp;
- }
- string stringab(string a[],int c)
- {
- int i=0;
- string b;
- while (i<c)
- {
- b=a[i].substr(0,4);
- int j=0;
- int check=0;
- while (j<c)
- {
- if (i==j)
- {
- if ((j+1)!=c) j++;
- else
- {
- b="";
- return b;
- }
- }
- if (desi2(a[i])==desi2(a[j]))
- {
- b+=a[j].substr(0,4);
- check++;
- if (check==2) return b;
- }
- j++;
- }
- i++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement