fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. string s;
  8. cin>>s;
  9. int n = s.size();
  10. vector<int>arr(26);
  11. for(int i = 0 ; i<n;i++){
  12. int x = i ;
  13. int y = n-i-1;
  14. arr[s[i]-'a']+=(x+1)*(y+1);
  15. }
  16. int max_freq=INT_MIN;
  17. char c;
  18. for(int i = 0 ; i<26;i++){
  19. if(arr[i]>max_freq){
  20. max_freq = arr[i];
  21. c = char(97+i);
  22. }
  23. }
  24. cout<<c;
  25. // your code goes here
  26. return 0;
  27. }
Success #stdin #stdout 0s 5324KB
stdin
abca 
stdout
a