Advertisement
a53

ExtreageCuvant

a53
Oct 22nd, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. int extrageCuvant(char d[],char s[],char sep[],int nc)
  2. {
  3. int Ls=0;
  4. while(s[Ls]!='\0') ++Ls; /// Calculez lungimea sirului sursa Ls
  5. int Lsep=0;
  6. while(sep[Lsep]!='\0') ++Lsep; /// Calculez lungimea sirului de separatori Lsep
  7. int i=0,Ld=0; /// Ld = lungimea sirului destinatie (cuvantul gasit)
  8. bool ok=true; /// daca se va gasi un separator, atunci ok=true
  9. while(ok)
  10. {
  11. ok=false;
  12. for(int j=0;j<Lsep;++j)
  13. if(s[i]==sep[j])
  14. {
  15. ok=true;
  16. ++i;
  17. break;
  18. }
  19. }
  20. int nrc=0; /// nrc = numarul cuvantului gasit
  21. while(i<Ls)
  22. {
  23. ok=false;
  24. for(int j=0;j<Lsep&&!ok;++j)
  25. if(s[i]==sep[j])
  26. ok=true;
  27. if(ok) /// Daca am ajuns la un separator (deci am gasit un cuvant)
  28. {
  29. d[Ld]='\0'; /// g<<nrc<<' '<<d<<endl;
  30. if(nrc==nc) /// Daca am ajuns la cuvantul cautat
  31. return 1;
  32. ++i; /// Trec la urmatorul caracter
  33. ok=true; /// ca sa trecem peste ceilalti separatori (daca sunt mai multi intre cuvinte)
  34. while(ok)
  35. {
  36. ok=false;
  37. for(int j=0;j<Lsep;++j)
  38. if(s[i]==sep[j])
  39. {
  40. ok=true;
  41. ++i;
  42. break;
  43. }
  44. }
  45. Ld=0; /// Caut un nou cuvant
  46. ++nrc;
  47. }
  48. d[Ld++]=s[i++];
  49. }
  50. ok=false;
  51. for(int j=0;j<Lsep;++j)
  52. if(s[Ls-1]==sep[j])
  53. {
  54. ok=true;
  55. break;
  56. }
  57. /// g<<"NRC="<<nrc<<endl;
  58. if(!ok&&nc==nrc)
  59. return 1;
  60. d[0]=0;
  61. return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement