-
Notifications
You must be signed in to change notification settings - Fork 1
/
PLEXSORT.cpp
executable file
·119 lines (85 loc) · 1.75 KB
/
PLEXSORT.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#define FOR(i,a,b) for(int i = a ; i < b ; ++i )
#define PB push_back
using namespace std;
string pattern;
vector <string> tab;
bool comparator( string a, string b );
void qsort(int start,int stop );
int partition(int start, int stop);
int main(){
long long t;
long long n;
string temp;
char c;
ios_base::sync_with_stdio(false);
cin >> t;
FOR( i , 0 , t ){
cin >> pattern;
cin >> n ;
tab.resize( n + 100 );
FOR( j, 0, n ){
cin >> tab[ j ];
}
cin.get( c );
cin.get( c );
//sort( tab.begin(), tab.end() , comparator);
qsort(0,n-1);
FOR( j , 0 , n ){
cout << tab[ j ] << endl;
}
cout << endl;
//tab.clear();
}
return 0 ;
}
int partition(int start, int stop){
string pivot = tab[ start ];
int p = start;
FOR( i , start + 1, stop + 1 ){
if( comparator( tab[ i ], pivot) ){
p++;
swap( tab[ i ], tab[ p ] );
}
}
swap( tab[ p ], tab[ start ]);
return p;
}
void qsort( int start, int stop ){
if( start >= stop ) return;
int r = partition( start, stop );
qsort( start, r-1 );
qsort( r+1, stop );
}
bool comparator( string a, string b ){
int asize = a.length();
int bsize = b.length();
int iterator = 0 ;
if( a == b )
return true;
while ( iterator <= asize and iterator <= bsize ){
if( iterator == asize ){
return true;
}
else if( iterator == bsize ){
return false;
}
else{
int i = 0 ;
while( i < pattern.size() ){
if( pattern[ i ] == a[ iterator ] and pattern[ i ] != b[ iterator ] )
return true;
else if ( pattern [ i ] == b[ iterator ] and pattern [ i ] != a[ iterator ] )
return false;
i++;
}
}
iterator++;
}
return true;
}