
Untitled
By: a guest on
May 2nd, 2012 | syntax:
C++ | size: 1.61 KB | hits: 28 | expires: Never
#include <iostream>
#include <string.h>
using namespace std;
bool sottostring(string S1, string S2){
bool substring=false;
int i=0;
int L1=S1.length();
int L2=S2.length();
while( i<=(L1-L2) && !substring)
{
if(S1.substr(i,L2)==S2)
substring = true;
else
i++;
}
return substring;
}
int main()
{
cout<<"lavorare con le stringhe:\n";
cout<<"INERIRE\n"<<"1)sottotringa se vuoi vedere se una stringa e' sottostringa di un'altra;\n"<<"2) somma se vuoi sommare due stringhe;\n";
string S1;
string S2;
string SL1;
string SL2;
string input;
int sottostringa = 12;
int B = sottostringa;
int somma = 5;
int C = somma;
cout<<"inserisci consegna:\n";
cin>>input;
int A= input.length();
cout<<endl;
if(A == B)
{
cout<<"inserisci S1:\n";
getline(cin, S1);
cout<<endl;
cout<<"inserisci S2:\n";
getline(cin,S2);
if(sottostring(S1,S2))
{
cout<<S2<<" e' sottostringa di "<<S1;
cout<<"\n";
}else{
cout<<S2<<" non e' sottostringa di "<<S1;
}
}
if(A == C )
{
cout<<"inserisci SL1:\n";
cin>>SL1;
cout<<endl;
cout<<"inserisci SL2:\n";
cin>>SL2;
string SS3;
int LL1=SL1.length();
int LL2=SL2.length();
int LL3=LL1+LL2;
SS3=SL1+SL2;
cout<<"l'unione tra "<<SL1<<" e "<<SL2<<" e': "<<SS3<<";\n";
cout<<"la lunghezza di "<<SS3<<" e' "<<LL3<<";\n";
}
return 0;
}