1 / 41
Aug 2012

hello everyone i am fairly new to programming in c++ and i quite dont understand what the problem is asking you to do ?
also what is meant by brute force ?

  • created

    Aug '12
  • last reply

    Apr '21
  • 40

    replies

  • 5.5k

    views

  • 23

    users

  • 1

    like

  • 6

    links

Not another new programmer falling into the C++ trap! There have been worse languages, but not many.

Advantages of C++:
Good libraries
Disadvantages of C++:
A type system that is too wimpy to express anything interesting, so that typical code is riddled with type casts, but that nevertheless has undecidable type checking. This is in stark contrast to O'Caml, Haskell, and SML. Even Java does this better.

No type inference at all, so all variable types must be declared.

Horrid syntax

To go with the horrid syntax, an ancient, primitive macro system that is 1) hard to understand 2) non-hygienic, and 3) incapable of complex computations. For a proper macro system, see Scheme's syntax-case macro system.

thnx for the replies guys and those links really helped i thought about it again and the answer has been accepted smile

5 months later

whats the problem with this code:

include

int main()
{
int n;
while(scanf("%d", &n) && n!=42)
printf("%d\n", n);
printf("%d", n);
return 0;
}

1 year later

Hi, i am not able to find the error in my program. My code is as follows:
public class Life {
int inputArray[];
Life(int a[]){
inputArray=a;
}

void printResult(){
	System.out.println("Started");
	//System.out.println(inputArray[0]);
	for(int i=0;i<=inputArray.length-1;i++){
		if(inputArray[i]==42 &&(inputArray[i]>99)&&(inputArray[i]<-99))
			break;
		System.out.println(inputArray[i]);
	}
	System.out.println("FINISHED");
}
public static void main(String[] args) {
	int c[]={1,3,4,5,1,2,3,7,8,9,0,1,2,3,42,4,5,6,7,8,4};
	Life ob=new Life(c);
	ob.printResult();
	}
}

Welcome! Please use code tags when posting code. What language is this? What error is the judge returning?

[quote="leppy"]Hello leppy... This is Java.. I am new to programming world and I don't know about code tags.. Can you figure out the issue? Thanks for your response.

Your code should look like this.
click on code tag and paste your code between them.
and on SPOJ you should not use public before class if you are using public you class name should be main.

Your algorithm is completely wrong, what problem is asking is you have to print all number until you encounter 42 in the input. Input can be any integer value it is not only between 1 and 100,and no need to print Started or finished in the output you have to print only those things which problem is asking for.

Hope this helps.

class Life 
{
	int inputArray[];
	Life(int a[])
	{
		inputArray=a;
	}
	void printResult()
	{
		System.out.println("Started");
		//System.out.println(inputArray[0]);
		for(int i=0;i<=inputArray.length-1;i++)
		{
			if(inputArray[i]==42 &&(inputArray[i]>99)&&(inputArray[i]<-99))
			break;
			System.out.println(inputArray[i]);
		}
	System.out.println("FINISHED");
	}
	public static void main(String[] args)
	{
		int c[]={1,3,4,5,1,2,3,7,8,9,0,1,2,3,42,4,5,6,7,8,4};
		Life ob=new Life(c);
		ob.printResult();
	}
}

Hi Laxman...I have changed the code as directed by you and still getting the the wrong answer...

class Main {
	int inputArray[];
	Main(int a[]){
		inputArray=a;
	}
	void printResult(){
		for(int i=0;i<=inputArray.length-1;i++){
			if(inputArray[i]==42)
				break;
			System.out.println(inputArray[i]);
		}
	}
	public static void main(String[] args) {
		int c[]={42,3,4,5,1,2,3,7,8,9,0,1,2,3,4,5,6,7,8,4};
		Main ob=new Main(c);
		ob.printResult();
		}
	}

what is this "int c[]={42,3,4,5,1,2,3,7,8,9,0,1,2,3,4,5,6,7,8,4};"

your code prints nothing.

how you are reading the input? what are you doing with "c[]".

Read the problem statement once again.

Still you don't understand what problem is asking for.
answer my question.-->How you are reading the input?