Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4. typedef struct tableau {
  5. int t[20];
  6. int l;
  7.  
  8. };
  9.  
  10. tableau occ(tableau &a){
  11. tableau b;
  12. int i,k,j=1,T=a.t[0];
  13. b.t[0]=a.t[0];
  14. for(i=1;i<a.l;i++){
  15. if(a.t[i]!=T){
  16. b.t[j]=a.t[i];
  17. j=j+1;
  18. T=a.t[i];
  19.  
  20. }
  21. b.l=j;
  22. }
  23.  
  24. return b;
  25.  
  26.  
  27. }
  28.  
  29.  
  30. int simil(tableau &a,tableau &b)
  31. {
  32. int i ;
  33. if(a.l!=b.l){
  34. return 0;
  35. }
  36. for(i=0;i<a.l;i++){
  37. if(a.t[i]!=b.t[i]){
  38. return 0;
  39. }
  40. }
  41. return 1;}
  42.  
  43.  
  44.  
  45. void trier(tableau &a){
  46. int ok=1,i,j,tmp=0;
  47. while(ok!=0){
  48.  
  49. for(i=0;i<a.l;i++){
  50.  
  51. if(a.t[i+1]<a.t[i]){
  52. tmp=a.t[i];
  53. a.t[i]=a.t[i+1];
  54. a.t[i+1]=tmp;
  55. i=a.l+1;
  56. ok=1;
  57. }
  58. else{ok=0;
  59. }
  60. }
  61.  
  62. }
  63.  
  64. }
  65.  
  66. void remplir(tableau &a)
  67. {int i;
  68. printf("\n la taille : ");
  69. scanf("%d",&a.l);
  70. printf(" les elements du tabeau : ");
  71. for(i=0;i<a.l;i++){
  72. scanf("%d",&a.t[i]);
  73.  
  74. }
  75.  
  76. }
  77.  
  78.  
  79.  
  80. void afficher(tableau &a){
  81. int i;
  82. printf("\n votre tableau :\n");
  83.  
  84. for(i=0;i<a.l;i++){
  85.  
  86. printf(" %d ",a.t[i]);
  87. }
  88. }
  89.  
  90.  
  91.  
  92.  
  93. int egaux(tableau &a,tableau &b)
  94. {
  95. int i ;
  96. if(a.l!=b.l){
  97. return 0;
  98. }
  99. for(i=0;i<a.l;i++){
  100. if(a.t[i]!=b.t[i]){
  101. return 0;
  102. }
  103. }
  104. return 1;}
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112. main()
  113. {
  114. tableau t,s,y,z;
  115. int a,b,c;
  116. int i,j,tmp=0;
  117. //REMPLISSAGE
  118. printf("remplir les tableaux :");
  119. remplir(t);
  120. remplir(s);
  121. system("cls");
  122. //AFFICHAGE
  123. afficher(t);
  124. afficher(s);
  125.  
  126. //EGALITE
  127. a=egaux(t,s);
  128. if(a==0){
  129. printf("\n les tableaux sont diffenrents.");
  130. }
  131. else{printf("\n les tableaux sont egaux.\n ");}
  132.  
  133. //TRIE
  134. trier(t);
  135. trier(s);
  136.  
  137. //SIMILAIRE
  138. b=simil(t,s);
  139. if(b==0){
  140. printf("\n les tableaux ne sont pas silimaires.");
  141. }
  142. else{printf("\n les tableaux sont similaires. ");}
  143.  
  144. //occurence
  145. y=occ(t);
  146. z=occ(s);
  147.  
  148. //KIFKIF
  149. c=simil(z,y);
  150. if(c==0){
  151. printf("\n les tableaux ne sont pas compatibles.");
  152. }
  153. else{printf("\n les tableaux sont compatibles.\n ");}
  154.  
  155.  
  156.  
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement