Last active
December 14, 2015 07:29
-
-
Save kuoe0/5051092 to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int n; | |
while ( ~scanf( "%d", &n ) ) { | |
int x; | |
vector< int > num; | |
for ( int i = 0; i < n; ++i ) { | |
scanf( "%d", &x ); | |
num.push_back( x ); | |
} | |
bool flag = true; | |
for ( int i = 0; flag && i < n - 1; ++i ) { | |
flag = false; | |
for ( int j = 0; j < n - 1 - i; ++j ) | |
if ( num[ j ] > num[ j + 1 ] ) { | |
swap( num[ j ], num[ j + 1 ] ); | |
flag = true; | |
} | |
} | |
for ( int i = 0; i < num.size(); ++i ) | |
printf( "%d ", num[ i ] ); | |
puts( "" ); | |
} | |
return 0; | |
} |
This file contains 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 <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int n; | |
while ( ~scanf( "%d", &n ) ) { | |
int x; | |
vector< int > num; | |
for ( int i = 0; i < n; ++i ) { | |
scanf( "%d", &x ); | |
num.push_back( x ); | |
} | |
for ( int i = 0; i < n - 1; ++i ) | |
for ( int j = 0; j < n - 1 - i; ++j ) | |
if ( num[ j ] > num[ j + 1 ] ) | |
swap( num[ j ], num[ j + 1 ] ); | |
for ( int i = 0; i < num.size(); ++i ) | |
printf( "%d ", num[ i ] ); | |
puts( "" ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment