Search found 293 matches

by chunyi81
Wed Apr 26, 2006 5:51 am
Forum: Volume 4 (400-499)
Topic: 403 - Postscript
Replies: 28
Views: 3786

emotional blind, my AC code actually seg faults with your input. You can assume input is formatted correctly as described in the sample input and no blank lines. I ran the following input (it's the same as yours but removing blank lines and adding a space to avoid the seg fault. .C C5 3 |ACM| .C C5 ...
by chunyi81
Fri Apr 14, 2006 5:03 am
Forum: Volume 100 (10000-10099)
Topic: 10062 - Tell me the frequencies!
Replies: 235
Views: 37893

Did you test your code with the sample input? Your code does not even work for the sample input. I get the following output when I ran your code with the sample input: 012345678967 1 66 2 65 3 49 1 50 2 51 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Did you notice you have an extra cout in your code here: lon...
by chunyi81
Wed Apr 12, 2006 10:38 am
Forum: Volume 4 (400-499)
Topic: 482 - Permutation Arrays
Replies: 159
Views: 32309

I am so sorry :oops:

Yes I can see that part of your code is changing the index form char to integer. That part should be ok, my mistake.

Can someone else help please?
by chunyi81
Tue Apr 11, 2006 5:18 am
Forum: Volume 4 (400-499)
Topic: 482 - Permutation Arrays
Replies: 159
Views: 32309

This part of your code: // get the number while ( dataIndex[i] != ' ' && dataIndex[i] != '\n' && dataIndex[i] != '\0' ) { num *= 10; num += dataIndex[i] - 48; i++; } What if num += dataIndex - 48 >= 10? You never handle the carry.
by chunyi81
Sun Apr 09, 2006 5:36 am
Forum: Bugs and suggestions
Topic: c++ compiler problems
Replies: 3
Views: 2615

What compiler are you using? I got the following errors when I compiled with g++ 2.95.3: testing.cpp: In function `bool onseg(const point &, const complex<int> *)': testing.cpp:20: implicit declaration of function `int min(...)' testing.cpp:21: implicit declaration of function `int max(...)' testing...
by chunyi81
Sat Apr 08, 2006 5:53 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 189134

Also what if there are more than 10 test cases in the input? Your code will give RTE. Try to read and process one input at a time.
by chunyi81
Sat Apr 08, 2006 3:21 pm
Forum: Volume 1 (100-199)
Topic: 100 - The 3n + 1 problem
Replies: 1394
Views: 189134

There can be more than one test case enib.

What does your code output for:

Code: Select all

1 10
100 200
Enter the above two cases together, not separately. Your code will give all output in one line. You need to print a newline for each line of output.
by chunyi81
Mon Apr 03, 2006 4:47 am
Forum: Volume 1 (100-199)
Topic: 136 - Ugly Numbers
Replies: 156
Views: 19636

Delete the word "public" in front of "Main".

Hope this helps.

Putting the word public for a Java class is more useful when you have many packages and you need to make some classes in a package accessible to classes in another package.
by chunyi81
Fri Mar 31, 2006 11:16 am
Forum: Volume 100 (10000-10099)
Topic: 10038 - Jolly Jumpers
Replies: 445
Views: 82751

How does your code terminate when there is no more input?

You have a while(true) loop there but that is precisely causing time limit exceed. You can simply do this:

Code: Select all

while (cin >> numElements)
by chunyi81
Fri Mar 31, 2006 4:50 am
Forum: Volume 1 (100-199)
Topic: 147 - Dollars
Replies: 233
Views: 22458

It seems that these two lines are causing some problems: n = f/0.05; f is a double and divideing by 0.05 still gives a double but you are assiging to an int. You should explicitly cast f/0.05 to an int and not expect the OJ compiler to do it for you. Somehow it should but it doesn't. The other thing...
by chunyi81
Wed Mar 29, 2006 9:10 am
Forum: C++
Topic: counting even numbers
Replies: 5
Views: 2322

Thanks Krzysztof for correcting my mistakes. :oops:
by chunyi81
Tue Mar 28, 2006 6:32 am
Forum: Volume 4 (400-499)
Topic: 401 - Palindromes
Replies: 196
Views: 32652

One more thing I did not point out is that you are checking the return value of scanf with EOF. Try changing that to

Code: Select all

while(scanf("%s",ciag) == 1)
Checking with EOF can sometimes give problems as the last input might only have a end-of-line rather than end-of-file.
by chunyi81
Mon Mar 27, 2006 5:33 am
Forum: Volume 4 (400-499)
Topic: 401 - Palindromes
Replies: 196
Views: 32652

Your code looks ok to me. Did you try testing your code with a string of exactly 20 characters? Your char array has a size 20, but you need a size of 21 to hold the NULL character as well as to hold a string of length 20. This is in the only problem I see.
by chunyi81
Sun Mar 26, 2006 5:38 am
Forum: Volume 4 (400-499)
Topic: 492 - Pig-Latin
Replies: 213
Views: 26644

Try this input: This is the input. This.is.the.input. 2 spaces separate each word for the first line. And for the second line, the period '.' separates each word. Your code will fail for these test cases because you used strtok. You are assuming only 1 space separate each word. The problem descripti...
by chunyi81
Sun Mar 26, 2006 5:29 am
Forum: C++
Topic: counting even numbers
Replies: 5
Views: 2322

Looks like an operator precedence problem. Expressions in C++ are evaluated from right to left and logical operators always have a higher precedence in evaluating an expression, which means that in the first code, 2 && cout << i << endl is evaluated first -> this always give 1. Now the while loop co...

Go to advanced search