Advertisement
RusSimona

pg 160 ex 39

Jun 21st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<iostream>
  2. #include<string.h>
  3. #include<fstream>
  4.  
  5. using namespace std;
  6.  
  7. ifstream fin("text.in");
  8. //ofstream fout("text.out");
  9.  
  10. int ordalfa ( char a[51])
  11. {
  12. int ok=1, i;
  13.  
  14. for(i=0; i<strlen(a)-1; i++)
  15. if (a[i]>a[i+1])ok=0;
  16.  
  17. if(ok) return 1;
  18. else return 0;
  19. }
  20.  
  21. char s[51][51], rez1[51], rez2[51];
  22. int main ()
  23.  
  24. {
  25. int n, i, nr=0;
  26. fin>>n;
  27.  
  28. for(i=1;i<=n;i++)
  29. fin>>s[i];
  30.  
  31. for(i=1;i<n;i++)
  32. {
  33. strcpy(rez1, s[i]);
  34. strcat(rez1, s[i+1]);
  35. strcpy(rez2, s[i+1]);
  36. strcat(rez2, s[i]);
  37. if(ordalfa(rez1)||ordalfa(rez2)) nr++;
  38. }
  39. cout<<nr;
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement