Skip to content

Instantly share code, notes, and snippets.

@antonshilov
Created May 19, 2015 11:51
Show Gist options
  • Save antonshilov/256c9ce7ce1cec0b33e4 to your computer and use it in GitHub Desktop.
Save antonshilov/256c9ce7ce1cec0b33e4 to your computer and use it in GitHub Desktop.
#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