Page 30 of 30
Re: 10038 - Jolly Jumpers
Posted: Thu Dec 11, 2014 9:23 pm
by Echoless
I tried all given inputs, and it still gives me a wrong answer. Anyone can tell me what's the problem?
Code: Select all
Tweaked it myself and it finally gave me accepted:)
Re: 10038 - Jolly Jumpers
Posted: Wed Dec 17, 2014 5:09 pm
by Lim.YuDe
I have looked at many posts in this thread and tried all sample input, and also tried the critical input as given on udebug.com, and although I pass all this input I get WA when I submit my code.. does anybody have any idea?
Re: 10038 - Jolly Jumpers
Posted: Wed Dec 17, 2014 10:06 pm
by brianfry713
Change line 21 from:
memset(numbers, 0, 3000);
to:
memset(numbers, 0, sizeof(numbers));
http://www.cplusplus.com/reference/cstring/memset/
The third argument is the number of bytes, an int is 4 bytes.
Re: 10038 - Jolly Jumpers
Posted: Thu Dec 18, 2014 3:16 am
by Lim.YuDe
Thank you Brianfry713! Just got AC!
Re: 10038 - Jolly Jumpers_Java Runtime Error
Posted: Mon Dec 29, 2014 11:15 am
by qz63
Hi guys. I have a problem in this question. I keep getting a Runtime Error. Would you guys have a look at my code and give some advice? Thanks. Here is my code.
Re: 10038 - Jolly Jumpers
Posted: Tue Dec 30, 2014 9:46 am
by lighted
Don't think that input ends with 0 or negative number. You should check if input has next int.
Code: Select all
if (input.hasNextInt())
n = input.nextInt();
else
break;
Re: 10038 - Jolly Jumpers
Posted: Tue Dec 30, 2014 9:56 am
by qz63
Thanks, lighted. I just figured it out like what you said. Thanks anyway.
I can't make it work in UVa's judge
Posted: Sun Apr 19, 2015 7:40 pm
by franmzy
Hi everyone!
I've been solving problems acording the programming-challenges site judge and when I tried to solve the Jolly Jumpers problem with the UVa judge I got WA.
I've tried every set of tests you suggestes and I get the correct answers.
I'd be pleased if you could help me to find my error. Here's my C ANSI code, I've used binary operations to solve it.
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char const *argv[])
{
long int n, i, num, ant;
unsigned long int target, counter;
char c;
while(scanf("%ld", &n) != EOF){
if (n<=0)
{
while((c = getchar()) != '\n' && (c = getchar()) != EOF);
printf("Not jolly\n");
continue;
}
target = pow(2,n)-1; // Example if n = 4 -> target = 1111 -> counter = 0001
counter = 1; // positions 3, 2, 1 need to be filled to get a Jolly number
scanf(" %ld", &ant);
for (i = 1; i < n; ++i)
{
scanf(" %ld", &num);
counter = (counter | (unsigned long int)pow(2,abs(ant - num)));
ant = num;
}
while((c = getchar()) != '\n' && (c = getchar()) != EOF);
if (target == counter)
{
printf("Jolly\n");
}
else
{
printf("Not jolly\n");
}
}
return 0;
}
Re: 10038 - Jolly Jumpers
Posted: Mon Aug 31, 2015 10:47 am
by Zedi
I got Runtime Error on UVA, WA on Programming Challenges.
Any recommendation for my code or test case will be appreciated!
TY
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
int nums[3000];
int num_checks[3000];
int num;
char ch;
char char_num[4];
char line[10000];
while (1){ // 케이스 별
int i = 0;
//int exit = 0;
int jolly = 1;
while ( !((ch = getchar()) == ' ' )){ // 처음 숫자를 입력받는다.
char_num[i++] = ch;
if (ch == '\n') break;
}
if (char_num[0] == '\n') break;
num = atoi(char_num);
if (ch == '\n') {
if (num == 1) puts("Jolly");
else puts("Not jolly");
continue;
}
for (i = 0; i < num; i++){
scanf("%d", &nums[i]);
//getchar(); // 스페이스바
//printf("%d ", nums[i]);
if (i != num - 1) // 인덱스가 0 ~ num - 2 까지 되도록
num_checks[i] = i + 1; // 들어간 숫자는 1 ~ num - 1
}
int index;
for (i = 1; i < num; i++){
index = abs(nums[i] - nums[i - 1]) - 1;
if (index >= num - 1 || index == -1 || num_checks[index] == 0){
jolly = 0;
break;
}
num_checks[index] = 0;
}
gets(line);
if (jolly) puts("Jolly");
else puts("Not jolly");
}
return 0;
}
Re: 10038 - Jolly Jumpers
Posted: Fri Dec 11, 2015 9:46 pm
by saadmanheavy
What is wrong with this code:
Code: Select all
#include <stdio.h>
#include <math.h>
int main()
{
int n;
int ar[3001];
while(scanf("%d", &n)!=EOF)
{
int ar1[n-1],i,flag=0;
for(i=0; i<n; i++)
{
scanf("%d", &ar[i]);
}
for (i=0; i<n; i++)
{
ar[i]=abs(ar[i]);
}
int j=0,k=0;
for(i=0; i<n-1; i++)
{
if(ar[j]>ar[j+1])
{
ar1[k]=ar[j]-ar[j+1];
j++;
k++;
}
else
{
ar1[k]=ar[j+1]-ar[j];
j++;
k++;
}
}
for(i=0;i<n-1;i++){
printf("%d ", ar1[i]);
}
i=0;
while(i<n-2){
if(ar1[0]!=n && ((ar1[i]-ar1[i+1]==0)||(ar1[i]-ar1[i+1]==1))&& ar1[n-2]==1){
flag=1;
}
i++;
}
if(flag==1)printf("Jolly\n");
else printf("Not Jolly\n");
}
return 0;
}
10038 - Jolly Jumpers
Posted: Fri Apr 29, 2016 5:44 pm
by souravvv
I am getting RTE. WHY
Code: Select all
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
typedef long long int lli;
int main(){
lli n,temp,index;
vector <lli> data;
vector <bool> check;
bool result;
while( 1 ){
cin >> n;
if( n == 0 )
break;
check.clear();
data.clear();
result = true;
for( lli i = 0; i < n; i++ ){
cin >> temp;
data.push_back( temp );
}
for( lli i = 0; i < n - 1; i++ ){
check.push_back( false );
}
for( lli i = 1; i < n; i++ ){
index = abs( data[i] - data[i - 1] ) - 1;
if( index <= (n - 2 ) )
check[ index ] = true;
}
for( lli i = 0; i < check.size(); i++ ){
if( check[i] == false )
result = false;
}
if( result )
cout << "Jolly" << endl;
else
cout << "Not jolly" << endl;
}
}