0% found this document useful (0 votes)
54 views19 pages

Informatica

The document contains C++ code snippets for string manipulation problems. The code snippets take a string as input, perform some operations on the string like replacing characters, reversing substrings, counting characters, and output the result.

Uploaded by

DianaUngureanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views19 pages

Informatica

The document contains C++ code snippets for string manipulation problems. The code snippets take a string as input, perform some operations on the string like replacing characters, reversing substrings, counting characters, and output the result.

Uploaded by

DianaUngureanu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Caractere-infosuport

28.

#include <iostream>

#include<cstring>

using namespace std;

char s[21],cop[21],voc[]= {'a','e','i','o','u'},x;

int i,j,ok;

int main()

cin>>s;

for(i=0; i<4; i++)

x=voc[i];

ok=0;

strcpy(cop,s);

for(j=0; j<strlen(cop); j++)

if(cop[j]==x)

ok=1;

strcpy(cop+j,cop+j+1);

if(ok==1)

cout << cop<<endl;

return 0;

}
29.

#include <iostream>

#include<cstring>

using namespace std;

char c1,c2,s[251];

int i;

int main()

cin>>c1;

cin.get();

cin>>c2;

cin.get();

cin.get(s,251);

cout<<s<<endl;

for(i=0; i<strlen(s); i++)

if(s[i]==c1)

s[i]=c2;

else if(s[i]==c2)

s[i]=c1;

cout <<s;

return 0;

30.

#include <iostream>

#include<cstring>

using namespace std;


char s[251];

int i;

int main()

cin.get(s,256); s[0]=s[0]-32; s[strlen(s)-1]=s[strlen(s)-1]-32;

for(i=1;i<strlen(s)-1;i++)

if(s[i]!=' '&&(s[i+1]==' '||s[i-1]==' '))

s[i]-=32;

cout<<s;

return 0;

31.

#include <iostream>

#include<cstring>

using namespace std;

char s[251],*p,voc[]="aeiou",nou[251];

int i;

int main()

cin.get(s,256);

p=strtok(s," ");

while(p)

if(strchr(voc,p[0]))

strrev(p);
strcat(nou,p);

strcat(nou," ");

else

{strcat(nou,p);

strcat(nou," ");

p=strtok(NULL," ");

cout<<nou;

return 0;

32.

#include <iostream>

#include<cstring>

using namespace std;

char s[251],*p,nou[251],cop[10],*q;

int i,nr;

int main()

cin.get(s,256);

p=strtok(s,"*");

while(p)

nr++;

if(nr==1)

strcpy(cop,p);

strcat(nou,"*");
strcat(nou,"*");

else

if(strcmp(p,cop)>0||strcmp(p,cop)<0)

strcat(nou,p);

strcat(nou,"*");

else

strcat(nou,"*");

p=strtok(NULL,"*");

cout<<nou;

return 0;

33.

#include <iostream>

#include<cstring>

using namespace std;

char s[41],voc[]="aeiou";

int i;

int main()

{cin>>s;

for(i=0;i<strlen(s);i++)

{
if(strchr(voc,s[i]))

cout<<s[i]<<" ";

return 0;

34.

#include <iostream>

#include<cstring>

using namespace std;

char s[41],cop[41];

int i;

int main()

{cin>>s;

for(i=0;i<strlen(s);i++)

{ strcpy(cop,s);

strcpy(cop+i,cop+i+1);

cout<<cop<<endl;

return 0;

35.

#include <iostream>

#include<cstring>

using namespace std;

char s[101],voc[]="aeiou",nou[101],*p;
int i;

int main()

{cin.get(s,101);

p=strtok(s," ");

while(p)

for(i=0;i<strlen(p);i++)

if(strchr(voc,p[i]))

p[i]+=1;

{strcat(nou,p);

strcat(nou," ");

p=strtok(NULL," ");

cout<<nou;

return 0;

36.

#include <iostream>

#include<cstring>

using namespace std;

char s[21],voc[]="aeiou";

int i;

int main()

{cin>>s;

for(i=0;i<strlen(s);i++)

{
if(strchr(voc,s[i])==NULL)

strcpy(s+i,s+i+1);

cout<<s;

return 0;

37.

#include <iostream>

#include<cstring>

using namespace std;

char s[21],voc[]="aeiou";

int i,nr;

int main()

{cin>>s;

for(i=0;i<strlen(s);i++)

if(strchr(voc,s[i]))

strcpy(s+i,s+i+1);

break;

for(i=0;i<strlen(s);i++)

if(strchr(voc,s[i]))

nr=i;

}
strcpy(s+nr,s+nr+1);

cout<<s;

return 0;

42.

#include <iostream>

#include<cstring>

using namespace std;

char s[51],*p,nou[51];

int i,ok;

int main()

{cin.get(s,101);

p=strtok(s," ");

while(p)

{ok=0;

for(i=0;i<strlen(p);i++)

if(p[i]>='a'&&p[i]<='z')

ok=1;

else

ok=0; break;

if(ok==1)

strcat(nou,p);

p=strtok(NULL," ");

cout<<nou;

return 0;
}

43.

#include <iostream>

#include<cstring>

using namespace std;

char s[51];

int fr[10],maxim,i;

int main()

{cin.get(s,51);

for(i=0;i<strlen(s);i++)

if(s[i]>='0'&&s[i]<='9')

fr[s[i]-'0']++;

for(i=0;i<=9;i++)

if(fr[i]>maxim)

maxim=fr[i];

for(i=0;i<=9;i++)

if(fr[i]==maxim)

cout<<i;

break;

}
}

return 0;

44.

#include <iostream>

#include<cstring>

using namespace std;

char s[51];

int fr[27],maxim,i;

int main()

{cin.get(s,51);

for(i=0;i<strlen(s);i++)

if(s[i]>='a'&&s[i]<='z')

fr[s[i]-'a']++;

for(i=1;i<=26;i++)

if(fr[i]>maxim)

maxim=fr[i];

if(maxim)

for(i=1;i<=26;i++)

{
if(fr[i]==maxim)

cout<<(char)(i+'a');

break;

else

cout<<"nu";

return 0;

45.

#include <iostream>

#include<cstring>

using namespace std;

char s[256];

int fr[26],i;

int main()

{cin.get(s,256);

for(i=0;i<strlen(s);i++)

if(s[i]>='a'&&s[i]<='z')

fr[s[i]-'a']++;

for(i=0;i<strlen(s);i++)

if(fr[s[i]-'a']>0)
{

cout<<s[i]<<" ";

fr[s[i]-'a']=0;

return 0;

46.

#include <iostream>

#include<cstring>

using namespace std;

char s[201],voc[]="aeiouAEIOU",*p;

int nrvoc;

int main()

{cin.get(s,201);

p=strtok(s," ");

while(p)

{if(strchr(voc,p[0])&&strchr(voc,p[strlen(p)]))

nrvoc++;

p=strtok(NULL," ");

cout << nrvoc;

return 0;

47.
#include <iostream>

#include<cstring>

using namespace std;

char s[51],nou[51];

int i,nr,j,poz;

int main()

{cin>>s;

for(i=0;i<strlen(s);i++)

nou[++nr]=s[i];

poz=0;

for(i=0;i<nr;i++)

for(j=0;j<=poz;j++)

cout<<s[j];

cout<<endl;

poz++;

return 0;

48.

#include <iostream>

#include<cstring>

using namespace std;

char s[256],c[21],*p,nou[256];

int i,j;
int main()

{cin.get(s,101);

cin.get();

cin.get(c,21);

p=strstr(s,c);

while(p)

for(i=0;i<strlen(c);i++)

*p='*';

p++;

p=strstr(p,c);

cout<<s;

return 0;

49.

#include <iostream>

#include<cstring>

using namespace std;

char s[101][256],voc[]="aeiou";

int n,j,v[101],minn=256,imin,i;

int main()

{cin>>n;

cin.get();

for(i=1;i<=n;i++)

cin.getline(s[i],256);
}

for(i=1;i<=n;i++)

for(j=0;j<strlen(s[i]);i++)

if(strchr(voc,s[i][j]))

v[i]++;

for(i=1;i<=n;i++)

if(v[i]<=minn)

minn=v[i];

imin=i;

cout << s[imin];

50.

#include <iostream>

#include<cstring>

using namespace std;

char s[51];

int i;

int main()

cin.get(s,51);

s[0]-=32;

for(i=1;i<strlen(s);i++)

if(s[i]!=' '&&(s[i+1]==' '||s[i-1]==' '||s[i+1]==NULL))

s[i]-=32;

cout<<s;

return 0;
}

51.

#include <iostream>

#include<cstring>

using namespace std;

char s[51],aux[51],voc[]="aeiouAEIOU";

int i;

int main()

cin.get(s,51);

for(i=0;i<strlen(s);i++)

{ if(strchr(voc,s[i]))

{strcpy(aux,s+i+1);

s[i+1]='*';

strcpy(s+i+2,aux);

cout<<s;

return 0;

52.

#include <iostream>

#include<cstring>

using namespace std;

char s[21];

int i,k;

int main()

cin.get(s,51);

k=strlen(s);

if(k%2==1)
for(i=0; i<k/2; i++)

swap(s[i],s[i+k/2+1]);

else

for(i=0; i<k/2; i++)

swap(s[i],s[i+k/2]);

cout<<s;

return 0;

55.

#include <iostream>

#include<cstring>

using namespace std;

char s[21],aux[21][21],*p;

int i,nr;

int main()

{cin.get(s,21);

p=strtok(s," ");

while(p)

strcpy(aux[++nr],p);

p=strtok(NULL," ");

swap(aux[2],aux[1]);

for(i=1;i<=nr;i++)

cout<<aux[i]<<" ";

return 0;
}

56.

You might also like