ICPC Is Coming In Hot!


This is a companion discussion topic for the original entry at https://toph.co/p/icpc-is-coming-in-hot

There’s a problem with the test cases. I got AC with this code,

    String ab = inp.next();
    char c [] = ab.toCharArray();
    int temp=0,storage;
    storage =0;
    for(int i=0;i<c.length ;i++)
    {
        int count =0;
        for(int j=0;j<c.length ;j++)
        {
            if(c[i]==c[j])
            {
                count++ ;
            }
        }
        if(count>storage)
        {
            storage =count;
            temp =c[i]-'0';
        }

    }
    System.out.println(temp);

It’s a number not a string.If i input 1213 in your code then 1213 will only store in index 0.

what is the test case 4?My code isn’t getting past test case 4.But i have checked my code for every posssible value it’s properly working.What’s the problem here please someone tell me.

1 Like

my code is not working for testcase 3 what is the problem?

#include<bits/stdc++.h>

using namespace std;

int main() {
	string s;
	cin >> s;
	int a[10];
    a[0] = count(s.begin(),s.end(),'0');
    a[1] = count(s.begin(),s.end(),'1');
	a[2] = count(s.begin(),s.end(),'2');
	a[3] = count(s.begin(),s.end(),'3');
	a[4] = count(s.begin(),s.end(),'4');
	a[5] = count(s.begin(),s.end(),'5');
	a[6] = count(s.begin(),s.end(),'6');
	a[7] = count(s.begin(),s.end(),'7');
	a[8] = count(s.begin(),s.end(),'8');
	a[9] = count(s.begin(),s.end(),'9');
	int max = *max_element(a,a+9);
	cout << a[max] << endl;
	return 0;
}

Plz check the last statement . Will your code work properly ?

#include
#include

using namespace std;

int main() {
int N = 0, count[10], num;

cin>>N;

for(int i = 0; i < 10; i++ ){
    count[i] = 0;
}

while(N != 0){
    num = N%10;
    count[num]++;
    N = N/10;
}

int max = count[0], max_digit = 0, max_digit_1 = 0;
for(int i = 0; i <= 9; i++){
    if(max == count[i] && max != 0){
        max_digit_1 = i;
    }
    if(max < count[i]){
        max = count[i];
        max_digit = i;
    }
}

if(max_digit_1 != 0){
    (max_digit < max_digit_1) ? cout<<max_digit<<endl : cout<<max_digit_1<<endl;
}else {
    cout<<max_digit<<endl;
}

return 0;

}

3rd case got wrong answer.