×

# Count of maximum-CHFMAX

 0 What is wrong in this code int main() { string str; int arr[256]={0}; int t; cin>>t; for(int i=0;i>str; for(int j=0;j=maxm&&arr[m]>0) { if(arr[m]==maxm) { if(m>pos) maxm=arr[pos]; } else { maxm=arr[m]; pos=m; } } } for(int j=0;j<256;j++) { if(arr[j]==maxm) {val=j; break; }} for(int i=0;i

 1 I think problem in you code is that you are not intialising array arr to 0 after every test case due to which previous frequencies of characters of old string are also getting added. answered 20 Nov '14, 18:56 4★zealf 1.1k●6●11●26 accept rate: 3%
 1 Declare int arr[256] = {0} inside for loop that is counting test case. i.e for(int i = 0; i < t;i++) { int arr[256] = {0}; //rest of the code.. }  This is because, if you do not initialise array values to zero for every test case, they take the values that remained in the array after previous test case. So count of frequency of characters differ. Ex : let this be input 2 aba abcd  With your code, frequencies of characters in second test case would give a = 3, b = 2, c = 1, d = 1. answered 20 Nov '14, 18:59 1.9k●2●14●30 accept rate: 24%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,476
×1,919
×856

question asked: 20 Nov '14, 17:38

question was seen: 1,169 times

last updated: 20 Nov '14, 19:06