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

Whats wrong with my code for http://www.codechef.com/problems/MAXCOUNT

$
0
0

include<iostream>

using namespace std;

void InsertionSort(long *arr,long n) {

long i,key;


for(long j=1;j<n;j++)
{
    i=j-1;
    key=arr[j];

    while(i>=0&&arr[i]>key)
    {
       arr[i+1]=arr[i];
       i--;
    }
    arr[i+1]=key;
}

}

void PrlongMaxRepeated(long *arr,long n) { long currentValue = arr[0]; long currentCount = 1; long maxValue = arr[0]; long maxCount = 1;

for(long i=1;i<n;i++) {="" if(arr[i]="=" currentvalue)="" {="" currentcount++;="" }="" else="" {="" is="" this="" greater="" than="" max="" count="" if(currentcount=""> maxCount) { maxCount = currentCount; maxValue = currentValue; }

// reset values
currentValue = arr[i];
currentCount = 1;

} }

cout<<maxValue<<" "<<maxCount<<endl;

}

int main() {

long TestCases; cin>>TestCases;

long A = new long[TestCases];; long size = new long[TestCases];

long j=0;

while(true) { long n; cin>>n; size[j]=n; A[j]= new long[n];

for(long i=0;i<n;i++)
{
    cin>>A[j][i];
}

j++;

if(j==TestCases)
    break;

}

for(long i=0;i<TestCases;i++) {
InsertionSort(A[i],size[i]); }

for(long i=0;i<TestCases;i++) {
PrlongMaxRepeated(A[i],size[i]); }

/*for(long i=0;i<TestCases;i++) {

for(long j=0;j<size[i];j++)
{
    cout<<A[i][j];
}
cout<<endl;

}*/

return 0;

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



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