Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- #include<algorithm>
- #include<vector>
- using namespace std;
- int veccmp(vector<char> a , vector<char> b){
- int i = 0;
- while(i < 9 && a[i] == b[i]){
- i++;
- }
- if(i == 9)return 0;
- return (a[i] > b[i] ? 1 : -1);
- }
- int main()
- {
- char str[10] = {"abcdefghi"};
- vector<char> vec;
- for(int i = 0 ; i < strlen(str) ; i ++){
- vec.push_back(str[i]);
- }
- vector< pair <vector <char> ,int> > vect;
- int page = 1;
- do{
- vect.push_back({vec,page});
- page++;
- }while(next_permutation(vec.begin(),vec.end()));
- int n;
- scanf("%d",&n);
- for(int i = 0 ; i < n ; i ++){
- scanf("%s",str);
- vector<char> newstr;
- for(int j = 0 ; j < 10 ; j ++)newstr.push_back(str[j]);
- int l = 0 , r = vect.size() - 1;
- while(l <= r){
- int m = (l+r)/2;
- int result = veccmp(newstr,vect[m].first);
- if(result == 1){
- l = m + 1;
- }
- else if(result == -1){
- r = m - 1;
- }
- else{
- printf("%d\n",vect[m].second);
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment