123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 | // #include <cstdio> // #include <cmath> // #include <ctime> // #include <cstdlib> // #include <algorithm> // using namespace std; // void fun(int * tab, int n) // { // int pom,hi,lo,test; // for(int i=0;i<n;i++) // { // pom=tab[i]; // hi=(pom & 0xff00); // lo=(pom & 0xff); // tab[i]=(lo<<4)|(hi>>4); // } // } // bool sortowanie (int i,int j) // { // return (i>j); // } // int main (){ // srand(1); // int godziny1,minuty1,sekundy1; // int godziny2,minuty2,sekundy2; // scanf("%d:%d:%d",&godziny1,&minuty1,&sekundy1); // scanf("%d:%d:%d",&godziny2,&minuty2,&sekundy2); // float n=abs(minuty1-minuty2); // float maks=abs((godziny1*3600)-(godziny2*3600)); // float x=maks/255; // unsigned int a[n]; // for(int i=0; i<n; i++) // { // a[i]=(rand()%(x+1)); // } // fun(*a,n); // sort(a,a+n,sortowanie); // for(int z=0; z<n; z++) // { // printf("%f\n",a[z]); // } // return 0; // } #include <iostream> #include <string> struct TimeStructure { int h; int m; int s; }; int getTimeInSeconds(TimeStructure input); void switchBits(unsigned char* tab, int n); void sortDescending(unsigned char* tab, int n); int main() { std::string temp; int numberOfTimes = 2; TimeStructure* times = new TimeStructure[numberOfTimes]; for (int i = 0; i < numberOfTimes; i++) { std::cin >> temp; times[i].h = std::stoi(temp.substr(0, 2)); times[i].m = std::stoi(temp.substr(3, 2)); times[i].s = std::stoi(temp.substr(6, 2)); } int n = abs(times[0].m - times[1].m); int max = abs(getTimeInSeconds(times[0]) - getTimeInSeconds(times[1])); unsigned char* A = new unsigned char[n]; int X = max % 255; srand(1); for (int i = 0; i < n; i++) A[i] = (rand() % X) + 1; switchBits(A, n); sortDescending(A, n); for (int i = 0; i < n; i++) std::cout << (int)A[i] << ' '; } int getTimeInSeconds(TimeStructure input) { return (input.h * 60 + input.m)*60 + input.s; } void switchBits(unsigned char* tab, int n) { unsigned char a, b; for (int i = 0; i < n; i++) { a = tab[i] << 4; b = tab[i] >> 4; tab[i] = a | b; } } void sortDescending(unsigned char* tab, int n) { unsigned char temp; for (int i = 0; i < n-1; i++) { for (int j = 0; j < n - i - 1; j++) { if (tab[j] < tab[j + 1]) { temp = tab[j]; tab[j] = tab[j + 1]; tab[j + 1] = temp; } } } } |