/*
Se citesc doua siruri de numere intregi, fiecare sir citindu-se pana la
intalnirea numarului 0 (numarul zero nu face parte din sir). Sa se verifice
daca cele doua siruri formeaza doua multimi de numere direct proportionale sau
invers proportionale.
Hint:
Elementele celor doua siruri le memoram in doi vectori notati cu A si B.
Daca cei doi vectori au numar diferit de elemente atunci nu se poate
vorbi despre proportionalitate. Trebuie sa formam perechi cu Elementele
celor doi vectori (o pereche fiind formata dintr-un element al vectorului A si
un element al vectorului B) astfel incat rapoartele (in cazul proportionalitatii
directe) si produsele (in cazul proportionalitatii inverse) perechilor sa fie egale.
Pentru aceasta ordonam elementele celor doi vectori in ordine crescatoare. In
cazul proportionalitatii directe o pereche este formata din elementele situate
pe aceeasi pozitie in cei doi vectori. In cazul proportionalitatii inverse se grupeaza
primul element din vectorul A cu ultimul element din vectorul B, al doilea element
din vectorul A cu penultimul element din vectorul B, etc...
*/
#include <stdio.h>
#define DIM 100
int arr[ DIM] , n, i,
arr2[ DIM] , m, j;
void countingSort( int * p, int n) {
int B[ 100 ] , C[ 100 ] ;
for ( int i = 1 ; i <= n; ++ i) C[ i] = p[ i] , B[ i] = 0 ;
for ( int i = 1 ; i < n; ++ i) {
for ( int j = i + 1 ; j <= n; j++ ) {
if ( C[ i] > C[ j] ) {
B[ i] ++;
} else {
B[ j] ++;
}
}
}
for ( int i = 1 ; i <= n; ++ i) p[ B[ i] + 1 ] = C[ i] ;
}
int main( int argc, char const * argv[ ] ) {
int x;
n = m = 0 ;
while ( x!= 0 ) {
arr[ ++ n] = x;
}
n--;
x = - 1 ;
while ( x!= 0 ) {
arr2[ ++ m] = x;
}
m--;
int est_dir_prop = 1 ,
est_inv_prop = 1 ;
//only the number of elements from first vector is equal with the number of element
//from second vector; otherwise doesn't work the solution
if ( n == m) {
//sort first vector
countingSort( arr, n) ;
//sort second vector
countingSort( arr2, n) ;
float correct = arr[ 1 ] / arr2[ 1 ] ;
//printf("%f", correct);
for ( i = 2 ; i <= n; ++ i) {
if ( ( float ) ( arr[ i] / arr2[ i ] ) != correct) {
est_dir_prop = 0 ;
}
}
correct = arr[ 1 ] * arr2[ n] ;
for ( i = 2 ; i <= n; ++ i) {
if ( arr[ i] * arr2[ n- i+ 1 ] != correct) {
est_inv_prop = 0 ;
break ;
}
}
if ( est_dir_prop
) printf ( "%s\n " , "Sunt direct proportionale!" ) ; else
printf ( "%s\n " , "Nu sunt direct proportionale!" ) ;
if ( est_inv_prop
) printf ( "%s\n " , "Sunt invers proportionale!" ) ; else
printf ( "%s\n " , "Nu sunt invers proportionale!" ) ;
} else {
printf ( "%s\n " , "Nu se poate face proportionalitatea!" ) ; }
return 0 ;
}
LyoKU2UgY2l0ZXNjIGRvdWEgc2lydXJpIGRlIG51bWVyZSBpbnRyZWdpLCBmaWVjYXJlIHNpciBjaXRpbmR1LXNlIHBhbmEgbGEKaW50YWxuaXJlYSBudW1hcnVsdWkgMCAobnVtYXJ1bCB6ZXJvIG51IGZhY2UgcGFydGUgZGluIHNpcikuIFNhIHNlIHZlcmlmaWNlCmRhY2EgY2VsZSBkb3VhIHNpcnVyaSBmb3JtZWF6YSBkb3VhIG11bHRpbWkgZGUgbnVtZXJlIGRpcmVjdCBwcm9wb3J0aW9uYWxlIHNhdQppbnZlcnMgcHJvcG9ydGlvbmFsZS4KSGludDoKRWxlbWVudGVsZSBjZWxvciBkb3VhIHNpcnVyaSBsZSBtZW1vcmFtIGluIGRvaSB2ZWN0b3JpIG5vdGF0aSBjdSBBIHNpIEIuCkRhY2EgY2VpIGRvaSB2ZWN0b3JpIGF1IG51bWFyIGRpZmVyaXQgZGUgZWxlbWVudGUgYXR1bmNpIG51IHNlIHBvYXRlCnZvcmJpIGRlc3ByZSBwcm9wb3J0aW9uYWxpdGF0ZS4gVHJlYnVpZSBzYSBmb3JtYW0gcGVyZWNoaSBjdSBFbGVtZW50ZWxlCmNlbG9yIGRvaSB2ZWN0b3JpIChvIHBlcmVjaGUgZmlpbmQgZm9ybWF0YSBkaW50ci11biBlbGVtZW50IGFs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gLy9wcmludGYoIiVmIiwgY29ycmVjdCk7CiAgICAgZm9yKGkgPSAyOyBpIDw9IG47ICsraSkgewoKICAgICAgICAgaWYoKGZsb2F0KShhcnJbaV0gLyBhcnIyWyBpIF0pICE9IGNvcnJlY3QpIHsKCiAgICAgICAgICAgZXN0X2Rpcl9wcm9wID0gMDsKICAgICAgICAgfQogICAgIH0KCiAgICAgY29ycmVjdCA9IGFyclsxXSAqIGFycjJbbl07CgogICAgIGZvcihpID0gMjsgaSA8PSBuOyArK2kpIHsKCiAgICAgICAgaWYoYXJyW2ldICogYXJyMltuLWkrMV0gIT0gY29ycmVjdCkgewogICAgICAgICAgICAgZXN0X2ludl9wcm9wID0gMDsKICAgICAgICAgICAgIGJyZWFrOwogICAgICAgIH0KICAgICB9CgogICAgIGlmKGVzdF9kaXJfcHJvcCkgcHJpbnRmKCIlc1xuIiwgIlN1bnQgZGlyZWN0IHByb3BvcnRpb25hbGUhIik7CiAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICAgIHByaW50ZigiJXNcbiIsICJOdSBzdW50IGRpcmVjdCBwcm9wb3J0aW9uYWxlISIpOwoKICAgICAgICAgICAgICAgICAgIGlmKGVzdF9pbnZfcHJvcCkgcHJpbnRmKCIlc1xuIiwgIlN1bnQgaW52ZXJzIHByb3BvcnRpb25hbGUhIik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBwcmludGYoIiVzXG4iLCAiTnUgc3VudCBpbnZlcnMgcHJvcG9ydGlvbmFsZSEiKTsKCiAgICB9IGVsc2UgewoKICAgICAgcHJpbnRmKCIlc1xuIiwgIk51IHNlIHBvYXRlIGZhY2UgcHJvcG9ydGlvbmFsaXRhdGVhISIpOwogICAgfQoKICByZXR1cm4gMDsKfQo=