#include <iostream> #include <vector> using namespace std; class QuickSort { private: vector<int> data; int Size; public: QuickSort(int n); void quick_sort(int left, int right); void print(); }; QuickSort::QuickSort(int n) { Size = n; for (int i = 0; i < Size; i++) { int x; cin >> x; data.push_back(x); } } void QuickSort::quick_sort(int left, int right) { int i, j, key, temp; if (left < right) { i = left + 1; j = right; key = data[left]; while (i <= j) { while (data[i] < key) { i++; if (i == data.size()) break; } while (data[j] > key) { j--; if (j == 0) break; } if (i <= j) { temp = data[i]; data[i] = data[j]; data[j] = temp; } } temp = data[left]; data[left] = data[j]; data[j] = temp; quick_sort(left, j - 1); quick_sort(j + 1, right); } } void QuickSort::print() { for (int i = 0; i < Size; i++) cout << data[i] << endl; } int main() { int Size; cin >> Size; QuickSort Q(Size); Q.quick_sort(0,Size-1); Q.print(); return 0; }
# include < iostream > # include < vector > using namespace std ; int Num_of_Divisor ( int n ) { int Count = 0 ; for ( int i = 1 ; i < = n ; i + + ) if ( n % i = = 0 ) Count + + ; return Count ; } int main ( ) { int Testcase ; cin > > Testcase ; while ( Testcase - - ) { int Rooms ; cin > > Rooms ; vector < int > Prisons ; for ( int i = 0 ; i < Rooms ; i + + ) Prisons . push_back ( 0 ) ; for ( int i = 1 ; i < Prisons . size ( ) + 1 ; i + + ) { if ( ( Num_of_Divisor ( i ) % 2 ) = = 0 ) Prisons [ i - 1 ] = 0 ; else Prisons [ i - 1 ] = 1 ; } int Fleer = 0 ; for ( int i = 0 ; i < Prisons . size ( ) ; i + + ) if ( Prisons ...
댓글
댓글 쓰기