Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

BEAUTIFUL STRINGS WA help:)

$
0
0

http://www.codechef.com/problems/WICQ8 question link and here is my code

#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include <string>   
#include <algorithm>
using namespace std;
int t,len,i,parentalpha[26],alphavalue,tp=26;
long long ans=0;
string A,B;

int main()
{

scanf("%d\n",&t);
while(t--)
{
    for(i=0;i<26;i++)
{
parentalpha[i]=0;
 }
    std::string str;
    std::getline(cin, str);
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    cout<<str<<"\n";
   len=str.length();
   for(i=0;i<len;i++)
  {
   if(int(str[i])>=97&&int(str[i])<=122)   
 {
alphavalue=(str[i])-97;
parentalpha[alphavalue]+=1;
}
}
for(i=0;i<26;i++)
{
 printf("%d ",parentalpha[i]);
 }
     cout<<"\n";
     std::sort(parentalpha, parentalpha + 26);
     for(i=0;i<26;i++)
{
printf("%d ",parentalpha[i]);
}
   cout<<"\n";
   for(i=25;i>=0;i--)
{
 ans=ans+(long long)(parentalpha[i]*tp);
 tp--;
}
  printf("%lld\n",ans);
}

return 0;
  }

dont know what i am doing wrong see the second test case :--- Good luck in the Facebook Hacker Cup this year! my program gives values of e=4 but it should be 3 moreover the output for 2nd case onward are -ve could u help guys!!!


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>