Last active
October 14, 2018 22:44
-
-
Save nimbus98/e340e9407052efa4708b3e0c47d21755 to your computer and use it in GitHub Desktop.
IEEE CodeBuddy | Week 2 | Aravind Sai K & Akash Nair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int fact(int n) | |
{ | |
int i = 0,ans = 1; | |
for(i=1;i<=n;i++) | |
{ | |
ans = ans*i; | |
ans = ans%1000003; | |
} | |
return ans; | |
} | |
int Solution::findRank(string A) { | |
int i=0,j,k,ans=0; | |
vector<int> arr; | |
while(A[i] != '\0') | |
{ | |
j = i; | |
k = 0; | |
while(A[j] != '\0') | |
{ | |
if(A[i] > A[j]) | |
k++; | |
j++; | |
} | |
arr.push_back(k); | |
i++; | |
} | |
k = 0; | |
i = arr.size()-1; | |
j = 0; | |
while(i >= 0) | |
{ | |
ans+=arr[i]*fact(j); | |
ans = ans%1000003; | |
j++; | |
i--; | |
} | |
return ans+1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment