AyaAbdelmoghith's blog

By AyaAbdelmoghith, history, 4 months ago, In English,

[ This is my code, I check it on Eclipse (The program I use to code) it works. However, I submitted here it doesn't work.][Here is the problem question](http://codeforces.com/contest/677/problem/A) ~~~~~ import java.util.Scanner;

public class AntonandDanik {

public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    Scanner string = new Scanner(System.in);
    int noGames= input.nextInt();
    String name = string.nextLine();//name.length()
    name=name.toUpperCase();
    int countA=0;
    int countD=0;
    char winner;
    for (int i=0; i<noGames;i++){
       winner= name.charAt(i);
       if (winner == 'A')
         countA++;
       else if (winner == 'D')
         countD++;
    }

    if (countA > countD)
       System.out.println("Anton");
    else if (countA < countD)
       System.out.println("Danik");
    else if (countA == countD)
       System.out.println("FriendShip");


}

} ~~~~~

 
 
 
 
  • Vote: I like it
  • +5
  • Vote: I do not like it

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Why do you use 2 scanners in the same input?

  • »
    »
    4 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I was doing only one scanner at the beginning. But, then it doesn't work! So, I tried with 2 scanners and it worked. So, I kept it like that.

    That was my code at the beginning Scanner input = new Scanner(System.in);

    int noGames= input.nextInt();
    String name = input.nextLine();
    • »
      »
      »
      4 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Just do next instead of nextLine.

      Or call nextLine twice, because it'll first read the empty line (after the integer) and the one you need after that.

  • »
    »
    4 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks for asking this question, because here was my mistake.

»
4 months ago, # |
  Vote: I like it 0 Vote: I do not like it

there is a problem with the code link but , I have edited it : here is the correct link the problem isn't with your solution , but the syntax in java is more complicated . try coding it using C++ and it will be more bugs free.....I tried hard to compile your code but , here is one of the top rated who use java . you can see his codes with java and learn from them Petr