Solution for CCC '15 J2 - Happy or Sad in Java 8


Nov. 6, 2019 2.810765 seconds Java 8
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        
                      Scanner in = new Scanner(System.in);
        String input = in.nextLine();
        //String[] array = input.split(" ");
        int count = 0;
        boolean has = false;
        
        for(int i = 0; i < input.length(); i++){
            if(input.charAt(i) == ':' && input.charAt(i + 1) == '-' ){
                if(input.charAt(i + 2) == ')'){
                  count++;  
                  has = true;
                }else if(input.charAt(i + 2) == '('){
                count--;
                has = true;
                }
        }
        
        }
        
        if(count > 0){
            System.out.println("happy");
        }else if(count < 0){
            System.out.println("sad");
        }else if(count == 0 && has){
            System.out.println("unsure");   
        }else{
            System.out.println("none");
        }
  
       

    }
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.