MCHAOS - Chaos Strings - SPOJ Solution C++

  Problem Link : MCHAOS 


👉 Hint : edit please

 


✅ C++ Solution :

 
#include<bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<string, null_type,less<string>, rb_tree_tag,tree_order_statistics_node_update> 
  

#define ll long long int
#define mp make_pair

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ordered_set o_set; 
	ll n,ans=0;
	cin>>n;
	string arr[n],s;
	for(int i=0;i<n;i++)
		cin>>arr[i];
	sort(arr,arr+n,greater<string>());
	reverse(arr[0].begin(),arr[0].end());
	o_set.insert(arr[0]);

	for(int i=1;i<n;i++)
	{
		s=arr[i];
		reverse(s.begin(),s.end());
		o_set.insert(s);
		ans+=o_set.order_of_key(s);
	
	}
	cout<<ans;
}

 

Thank you for your patience reading. If you enjoyed this post, I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Whatsapp or Facebook. 

😇Happy Learning!!