Advertisement
Zeinab_Hamdy

C

Sep 12th, 2022
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.89 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define ll long long
  3. #define ull unsigned long long
  4. #define nl cout<<"\n";
  5. #define sp cout<<" ";
  6. #define sz(x) x.size()
  7. #define NumOfDigit(w) log10(w) + 1
  8. #define fill(arr, val)  memset(arr, val , sizeof(arr))
  9. #define PI 3.141592654
  10. #define ceil(w, m) (((w) / (m)) + ((w) % (m) ? 1 : 0))
  11. #define all(v) v.begin(), v.end()
  12. #define rall(v) v.rbegin(), v.rend()
  13. #define fi first
  14. #define se second
  15. #define cin(v) for (auto&i:v) cin >> i;
  16. #define cout(v) for (auto&i:v) cout << i << " ";
  17. #define fixed(n) fixed << setprecision(n)
  18. using namespace std;
  19.  
  20. void zainab_hamdy(){
  21.     ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  22.     //freopen("filename.in" , "r" ,stdin);
  23. #ifndef ONLINE_JUDGE
  24.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27. bool prime(ll n){
  28.     if(n==2 || n==3) return true;
  29.     if(n<2 || n%2==0  ) return false;
  30.     for(int i=3;i<=sqrt(n);i+=2)   if(n%i==0) return false;
  31.     return true;
  32. }
  33.  
  34.  
  35. void isAccepted(){
  36.  string s ; cin >> s ;
  37.  int n=sz(s) , total=abs(s[n-1] - s[0] ) ;
  38.  char mn=min(s[0] , s[n-1]) , mx=max(s[0] , s[n-1]);
  39.  
  40. vector < pair <char , int >  > v ;
  41. for(int i=0 ; i<n ; i++) v.push_back({s[i] , i+1});
  42. sort(all(v));
  43.  
  44. vector < int > ans;
  45. cout << total << ' ';
  46.  
  47. if( s[0] <= s[n-1]){
  48.     for(int i = 0 ; i<sz(v) ;i++)
  49.         if (v[i].first >= s[0] and v[i].first <=s[n-1])
  50.                 ans.push_back(v[i].second);
  51.    
  52.              
  53. }else{
  54.     for(int i = sz(v)-1 ; i>=0 ;i--)
  55.         if (v[i].first >=s[n-1] and v[i].first <= s[0])
  56.                 ans.push_back(v[i].second);
  57.  
  58. }
  59. cout << sz(ans) << '\n';
  60.  
  61. for(auto& I : ans) cout << I << ' ';
  62.  
  63. nl
  64.  
  65. }
  66. int main(){
  67.                 zainab_hamdy();
  68.            
  69.     int testCase=1;  // one test case
  70.       cin >> testCase;
  71.     while(testCase--)
  72.         isAccepted();  // my code
  73.        
  74.     return 0;
  75. }
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement