HELP! CHEFDETECTIVE problem = ERROR IN COMPILATION

beginner
c-plus-plus
chefdete
practice
problem

#1

the problem in concern is https://www.codechef.com/problems/CHEFDETE

My program is not compiling and I cant seem to fix it. Could anyone help me understand and correct where and what is wrong syntactically or logically? any hekp ould be appreciated

this is my code in C++
#include<stdio.h>
using namespace std

int main()
{
int a,b,i,j,str[10000],rep[10000];
cin>>a;
for(i=0;i<a;i++)
{
str*=i+1;
cin>>rep*;
}
for(j=0;j<a;j++)
{
for(int k=0;k<a;k++)
{
if str[j]==rep[k]
{str[j]=-1;
 break;
 }
 }
 if str[j]!=-1;
 {cout<<str[j];}
 }
 }
 return 0;
 }

#2

I think this for loop will give you the complilation error. why you are using “=” in cin (I’m not clear)?

for(i=0;i<a;i++) {

="" str*=“i+1;”
cin="">>rep*;
}

You can check this solution. for reference.

Hope this helps!


#3

your header


#4

@srs101 The problem with your code is:

  1. Using wrong header file, use for “cin”

  2. Missing semicolon in 2nd line

  3. Bracket missing in “if” conditions

  4. Poor indentation

    #include
    #include<string.h>
    using namespace std;

    int main()
    {
    int a,b,i,j,str[10000],rep[10000];
    cin>>a;
    for(i=0;i<a;i++)
    {
    str*=i+1;
    cin>>rep*;
    }
    for(j=0;j<a;j++)
    {
    for(int k=0;k<a;k++)
    {
    if (str[j]==rep[k])
    {
    str[j]=-1;
    break;
    }
    }
    if (str[j]!=-1)
    {
    cout<<str[j]<<" ";
    }
    }
    return 0;
    }

I corrected your code. Have a look and compare it with your code and use indentation in your code it will help you in finding bugs easily.


#5

Did you tried to run it in codechef ide and see the error?


#6

Missing semi colon after using namespace std , no brackets for if statement, multiple errors.