import java.util.ArrayList;
import java.util.Scanner;

class Solution {

	public static void main(String[] args) throws Exception{
      // TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
		int T;
		T=Integer.parseInt(sc.nextLine());
	
		StringBuffer sb = new StringBuffer();
		
		for(int test_case = 1; test_case <= T; test_case++)
		{
			String s = sc.nextLine();
			ArrayList<Integer> al = new ArrayList<>();
			
			if(s.endsWith("north")) {
				s=s.substring(0,s.length()-5);
				al.add(0);
			}else{
				s=s.substring(0,s.length()-4);
				al.add(90);
			}
		
			int count=1;
			int sum =0;
			
			while(!s.equals("")) {
				if(s.endsWith("north")) {
					s=s.substring(0,s.length()-5);
					al.add(-90);
				}else{
					s=s.substring(0,s.length()-4);
					al.add(90);
				}
				count*=2;
			}
			
			String result = "";

			for(int i=0; i<al.size(); i++) {
				sum += al.get(i)*(Math.pow(2,al.size()-1-i));
			}
			
			while(sum%2==0 && count!=1) {
				sum/=2;
				count/=2;
			}
			
			if(count==1) {
				result = Integer.toString(sum);
			}else {
				result = Integer.toString(sum)+"/"+Integer.toString(count);
			}
			
			sb.append("#"+test_case+" "+result).append('\n');

		}
		System.out.print(sb);
	}
}

 

 

이거는 다시 복습해야겠다 .. 

 

for(int i=0; i<al.size(); i++) {
	sum += al.get(i)*(Math.pow(2,al.size()-1-i));
}

 

이 부분,, 생각 못했다 ^^

으앙 똥 멍충이냐구요 ~

'NOTE > SWEA' 카테고리의 다른 글

7193. 승현이의 수학공부 - d3  (0) 2022.06.16
7985. Rooted Binary Tree 재구성 - d3  (0) 2022.06.15
10993. 군주제와 공화제 - d3  (0) 2022.06.15
12051. 프리셀 통계 - d3  (0) 2022.06.12
13732. 정사각형 판정 - d3  (0) 2022.06.12

+ Recent posts