fork download
  1. import java.util.*;
  2. public class Main
  3. {
  4. public static void main(String[]args)
  5. {
  6. Scanner sc=new Scanner(System.in);
  7. int a=sc.nextInt();
  8. String c=sc.nextLine();
  9. char b[]=c.toCharrArray();
  10. int sea_level=0;
  11. int valley=0;
  12. for(int i=0;i<b.length;i++)
  13. {
  14. if(b[i]=='U')
  15. {
  16. sea_level++;
  17. }
  18. else
  19. {
  20. valley++;
  21. }
  22. }
  23. System.out.print(valley);
  24. }
  25. }
Success #stdin #stdout 0.03s 25904KB
stdin
Standard input is empty
stdout
import java.util.*;
public class Main
{
    public static void main(String[]args)
    {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        String c=sc.nextLine();
        char b[]=c.toCharrArray();
        int sea_level=0;
        int valley=0;
        for(int i=0;i<b.length;i++)
        {
            if(b[i]=='U')
            {
                sea_level++;
            }
            else
            {
                valley++;
            }
        }
        System.out.print(valley);
    }
}