Created
May 19, 2015 11:51
-
-
Save antonshilov/256c9ce7ce1cec0b33e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <windows.h> | |
#include <iostream> | |
#include <string> | |
using std::cout; | |
using std::cin; | |
using std::endl; | |
using std::string; | |
using std::to_string; | |
int main() | |
{ | |
srand(time(NULL)); | |
int size = 0; | |
cout << "Arr size: "; | |
cin >> size; | |
int* A = new int[size]; | |
for (int i = 0; i < size; i++) | |
A[i] = rand() % 100; | |
for (int i = 0; i < size; i++) | |
cout << A[i] << " "; | |
cout << endl; | |
string str; | |
DWORD StartTime = GetTickCount(); | |
for (int i = 0; i < size - 1; i++) | |
{ | |
if (A[i] > A[i + 1]) | |
{ | |
str = to_string(A[i]) + " "; | |
while (A[i] > A[i + 1]) | |
{ | |
str += to_string(A[i + 1]) + " "; | |
i++; | |
if (i == size - 1) | |
break; | |
} | |
cout << str << endl; | |
} | |
} | |
DWORD EndTime = GetTickCount(); | |
EndTime = EndTime - StartTime; | |
cout << "Exec time: " << EndTime << " millisec" << endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment