Skip to content

Instantly share code, notes, and snippets.

@kuoe0
Last active December 14, 2015 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kuoe0/5051092 to your computer and use it in GitHub Desktop.
Save kuoe0/5051092 to your computer and use it in GitHub Desktop.
#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;
}
#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