Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- typedef struct tableau {
- int t[20];
- int l;
- };
- tableau occ(tableau &a){
- tableau b;
- int i,k,j=1,T=a.t[0];
- b.t[0]=a.t[0];
- for(i=1;i<a.l;i++){
- if(a.t[i]!=T){
- b.t[j]=a.t[i];
- j=j+1;
- T=a.t[i];
- }
- b.l=j;
- }
- return b;
- }
- int simil(tableau &a,tableau &b)
- {
- int i ;
- if(a.l!=b.l){
- return 0;
- }
- for(i=0;i<a.l;i++){
- if(a.t[i]!=b.t[i]){
- return 0;
- }
- }
- return 1;}
- void trier(tableau &a){
- int ok=1,i,j,tmp=0;
- while(ok!=0){
- for(i=0;i<a.l;i++){
- if(a.t[i+1]<a.t[i]){
- tmp=a.t[i];
- a.t[i]=a.t[i+1];
- a.t[i+1]=tmp;
- i=a.l+1;
- ok=1;
- }
- else{ok=0;
- }
- }
- }
- }
- void remplir(tableau &a)
- {int i;
- printf("\n la taille : ");
- scanf("%d",&a.l);
- printf(" les elements du tabeau : ");
- for(i=0;i<a.l;i++){
- scanf("%d",&a.t[i]);
- }
- }
- void afficher(tableau &a){
- int i;
- printf("\n votre tableau :\n");
- for(i=0;i<a.l;i++){
- printf(" %d ",a.t[i]);
- }
- }
- int egaux(tableau &a,tableau &b)
- {
- int i ;
- if(a.l!=b.l){
- return 0;
- }
- for(i=0;i<a.l;i++){
- if(a.t[i]!=b.t[i]){
- return 0;
- }
- }
- return 1;}
- main()
- {
- tableau t,s,y,z;
- int a,b,c;
- int i,j,tmp=0;
- //REMPLISSAGE
- printf("remplir les tableaux :");
- remplir(t);
- remplir(s);
- system("cls");
- //AFFICHAGE
- afficher(t);
- afficher(s);
- //EGALITE
- a=egaux(t,s);
- if(a==0){
- printf("\n les tableaux sont diffenrents.");
- }
- else{printf("\n les tableaux sont egaux.\n ");}
- //TRIE
- trier(t);
- trier(s);
- //SIMILAIRE
- b=simil(t,s);
- if(b==0){
- printf("\n les tableaux ne sont pas silimaires.");
- }
- else{printf("\n les tableaux sont similaires. ");}
- //occurence
- y=occ(t);
- z=occ(s);
- //KIFKIF
- c=simil(z,y);
- if(c==0){
- printf("\n les tableaux ne sont pas compatibles.");
- }
- else{printf("\n les tableaux sont compatibles.\n ");}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement