#i dont think i understand this question too well

1 messages · Page 1 of 1 (latest)

slow bolt
#

this is more of a cp question than java, im doing a codeforce question that happens to be a part of an a2oj ladder im working my way through. this question says that there is 2 possible outputs for a certain input, but for some reason when i output any number besides the example, its wrong.

this is a link to the problem:
https://codeforces.com/problemset/problem/272/A

for the 1st and 3rd test my code does return 3 but for the 2nd test my code returns a 4 which should be acceptable if you look at the Note section at the bottom of the page. here is my code in java:

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Fingers {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int people = Integer.parseInt(input.readLine())+1, fCount = 0;
        StringTokenizer fingers = new StringTokenizer(input.readLine());
        for (int i = 0; i < people-1; i++) {
            fCount += Integer.parseInt(fingers.nextToken());
        }
        int dividend = fCount%people;
        if (dividend == 0) {
            System.out.println(fCount/people+1);
        } else {
            System.out.println(people+2-dividend);
        }
         
    }
}

i accept all criticisms (bad practice, incorrect algorithms, missed opportunities) as i am still getting into competitive programming.

ocean fjordBOT
# slow bolt this is more of a cp question than java, im doing a codeforce question that happ...

Detected code, here are some useful tools:

Formatted code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Fingers {
  public static void main(String[] args) throws IOException {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    int people = Integer.parseInt(input.readLine()) + 1, fCount = 0;
    StringTokenizer fingers = new StringTokenizer(input.readLine());
    for (int i = 0; i < people - 1; i++) {
      fCount += Integer.parseInt(fingers.nextToken());
    }
    int dividend = fCount % people;
    if (dividend == 0) {
      System.out.println(fCount / people + 1);
    }
    else {
      System.out.println(people + 2 - dividend);
    }
  }
}
#

<@&987246746478460948> please have a look, thanks.

slow bolt
#

sorry my mistake, that was code i messed around with trying to get the solution

#
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Fingers {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int people = Integer.parseInt(input.readLine())+1, fCount = 0;
        StringTokenizer fingers = new StringTokenizer(input.readLine());
        for (int i = 0; i < people-1; i++) {
            fCount += Integer.parseInt(fingers.nextToken());
        }
        System.out.println(people+2-(fCount%people)); 
    }
}
ocean fjordBOT
# slow bolt ``` import java.io.BufferedReader; import java.io.InputStreamReader; import java...

Detected code, here are some useful tools:

Formatted code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;

public class Fingers {
  public static void main(String[] args) throws IOException {
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    int people = Integer.parseInt(input.readLine()) + 1, fCount = 0;
    StringTokenizer fingers = new StringTokenizer(input.readLine());
    for (int i = 0; i < people - 1; i++) {
      fCount += Integer.parseInt(fingers.nextToken());
    }
    System.out.println(people + 2 - (fCount % people));
  }
}
slow bolt
#

this fits my description, gets me the 3 and 4

#

my bad i got it