thanks so much
1
3
1
0
1
0
6
9
0
Isâs right?
On my machine, your solution gives:
1
0
1
0
6
9
-57
so youâre obviously triggering some Undefined Behaviour somewhere.
Edit:
Ah - youâre not initialising any of the arrays:
int mang[N],phantu[N],soluong[N];
so their contents will be unpredictable.
Oh, thank you for your suggestions.
Could you please have a look on to this as well?
Looks like the same logic as used in the Editorial to me
hello
Can anyone tell me where I am getting the wrong answer in the following code :
#include <bits/stdc++.h>
using namespace std;
int main() {
int t,n;
cin>>t;
while(tâ)
{
int input=0;int i,c=0,max,j;
cin>>n;
vectorv;
for(i=0;i<n;i++)
{
cin>>input;
v.push_back(input);
}
sort(v.begin(),v.end());
for(i=0;i<n;i++)
{
max=v[i];
for(j=i+1;j<n;j++)
{
if(max==v[j])
{
c++;
}
}
}
if((c+1)==n)
cout<<0;
else if(c==0)
cout<<n-1;
else
cout<<n-(c+1);
}
return 0;
}
Please either format your code or link to your submission - the forum software has mangled it and it wonât compile!
I donât understand whats wrong with this. Can someone please help me figure it out. It throws WA.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
int x[n];
for(int i = 0; i < n; i++) {
cin >> x[i];
}
int ans[101] = {0};
for(int i = 0; i < n; i++) {
ans[x[i]]++;
}
int largest = -1;
for(int i = 0; i < 100; i++) {
largest = max(ans[i], largest);
}
cout << n - largest << endl;
}
}
could you explain what is the meaning of this line.
//can someone please tell me why is this code wrong? this is code link
https://www.codechef.com/viewsolution/36085318
#include < iostream>
using namespace std;
int main() {
// your code goes here
int t;
cin >> t;
while (tâ){
int n;
cin >> n;
char a[n];
for(int i=0; i<n; i++){
cin >> a[i];
}
int count=0, countmain=0,ele,step=0; // for finding max number of same same element.
for(int i=0; i<n; i++){ //count main is maxixmum no of same element
count=0;
for(int j=0; j<n; j++){
if(a[i]==a[j]) count++;
}
if (count > countmain){
countmain=count;
ele = a[i];
}
}
for(int j=0; j<=n; j++){
for(int i=0; i<n; i++){
if(a[i]==ele) continue;
else if (a[i-1]==ele){
a[i]=a[i-1];
step++;
}
else if (a[i+1]==ele) {
a[i]=a[i+1];
step++;
}
else continue;
}
}
cout << step << endl;
}
return 0;
}
awesome explanation