Advertisement
CosminVarlan

Untitled

May 1st, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. void eliminaUltimulA(char a[],char c)
  8. {
  9.     for(int i=strlen(a); i>=0; i--)
  10.     {
  11.         if (a[i]==c)
  12.         {
  13.             for (int j=i; a[j]!=0; j++)
  14.                 a[j]=a[j+1];
  15.             break;
  16.         }
  17.     }
  18. }
  19.  
  20. void pozitii(char s1[], char s2[])
  21. {
  22.     int gasit=1;
  23.     char *p=s1;
  24.     while(gasit)
  25.     {
  26.         gasit=0;
  27.         if (strstr(p,s2) !=0)
  28.         {
  29.             cout <<strstr(p,s2)-s1 << endl;
  30.             p = strstr(p,s2)+1;
  31.             gasit=1;
  32.         }
  33.     }
  34. }
  35.  
  36. int numar_aparitii(char s1[], char s2[])
  37. {
  38.     int c=0;
  39.     int gasit=1;
  40.     char *p=s1;
  41.     while(gasit)
  42.     {
  43.         gasit=0;
  44.         if (strstr(p,s2) !=0)
  45.         {
  46.             c++;
  47.             p = strstr(p,s2)+1;
  48.             gasit=1;
  49.         }
  50.     }
  51.     return c;
  52. }
  53.  
  54.  
  55. int main()
  56. {
  57.     char a[100]="Vrei sa pleci dar nu vrei sa ma iei sa vin cu tine.";
  58.  
  59.     pozitii(a," sa ");
  60.  
  61.  
  62.  
  63.     cout << numar_aparitii(a," sa ") << endl;
  64.  
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement