🔥Baekjoon start🔥

ariel·2021년 11월 15일
0

Baekjoon

목록 보기
8/14
post-thumbnail

2021-11-15

✍쪠와 함께 하루에 30분 이상 시작✨

1157

import java.util.Scanner;

public class Main {

		  public static void main(String[] args) {
	          int arr[] = new int[26]; //영문자의 개수
	          
	          Scanner sc = new Scanner(System.in);
	          String b = sc.next();
	          for(int i = 0; i<b.length(); i++) {
	        	  if('A'<= b.charAt(i)&& b.charAt(i) <= 'Z') {//대문자의 범위
	        		  arr[b.charAt(i) - 'A']++;//해당 인덱스의 값 1 증가
	        	  }else { //소문자의 범위
	        		  arr[b.charAt(i) - 'a']++;
	        	  }
	          }
	          
	          int max = -1;
	          char ch = '?';
	          
	          for(int i =0; i< 26; i++) {
	        	  if(arr[i] > max) {
	        		  max = arr[i];
	        		  ch = (char)(i+65); //캐스팅 필수 , 대문자로 출력하기 위해 65를 더해준다
	        	  }
	        	  else if(arr[i] == max) {
	        		  ch = '?';
	        	  }
	          }
	          System.out.print(ch);
	          
	          
	      }
}

1152

import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

		  public static void main(String[] args) {
	          int arr[] = new int[26]; //영문자의 개수
	          
	          Scanner sc = new Scanner(System.in);
	          String b = sc.nextLine();
	         
	          StringTokenizer st = new StringTokenizer(b, " ");
	          
	          System.out.println(st.countTokens());
    
	      }
}

2908

import java.util.Scanner;

public class Main {

		  public static void main(String[] args) {
	          Scanner sc = new Scanner(System.in);

	          int A = sc.nextInt();
	          int B = sc.nextInt();
	          
	         sc.close();
	         
	         A = Integer.parseInt(new StringBuilder().append(A).reverse().toString());
	         //생성과 동시에 메소드에 값을 입력 문자열을 뒤집어주고 반환시켜준다 
	         B = Integer.parseInt(new StringBuilder().append(B).reverse().toString());
	         
	         System.out.print(A > B ? A : B);
		  }
}

5622

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    
		Scanner in = new Scanner(System.in);
		
		String s = in.nextLine();
 
		int count = 0;
		int k = s.length();
        
		for(int i = 0; i < k; i++) {
        
			switch(s.charAt(i)) {
            
			case 'A' : case 'B': case 'C' : 
				count += 3;
				break;
                
			case 'D' : case 'E': case 'F' :
				count += 4; 
				break;
                
			case 'G' : case 'H': case 'I' :
				count += 5; 
				break;
                
			case 'J' : case 'K': case 'L' : 
				count += 6;
				break;
                
			case 'M' : case 'N': case 'O' :
				count += 7;
				break;
                
			case 'P' : case 'Q': case 'R' : case 'S' : 
				count += 8; 
				break;
                
			case 'T' : case 'U': case 'V' : 
				count += 9;
				break;
                
			case 'W' : case 'X': case 'Y' : case 'Z' : 
				count += 10;
				break;
			}
		}		
		System.out.print(count);
	}
}

2941

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
    
		Scanner in = new Scanner(System.in);
        
		String str = in.nextLine();
        
		int count = 0;
 
		for (int i = 0; i < str.length(); i++) {
 
			char ch = str.charAt(i);
 
			if(ch == 'c') {			// 만약 ch 가 c 라면?
				if(i < str.length() - 1) {
					if(str.charAt(i + 1) == '=') {		//만약 ch 다음 문자가 '=' 이라면?
						// i+1 까지가 하나의 문자이므로 다음 문자를 건너 뛰기 위해 1 증가
						i++;		
					}
					else if(str.charAt(i + 1) == '-') {
						i++;
					}
				}
			}
		    
			else if(ch == 'd') {
				if(i < str.length() - 1) {
					if(str.charAt(i + 1) == 'z') {
						if(i < str.length() - 2) {
							if(str.charAt(i + 2) == '=') {	// dz= 일 경우
								i += 2;
							}
						}
					}
		        
					else if(str.charAt(i + 1) == '-') {	// d- 일 경우
						i++;
					}
				}
			}
		    
			else if(ch == 'l') {
				if(i < str.length() - 1) {
					if(str.charAt(i + 1) == 'j') {	// lj 일 경우
						i++;
					}
				}
			}
		    
			else if(ch == 'n') {
				if(i < str.length() - 1) {
					if(str.charAt(i + 1) == 'j') {	// nj 일 경우
						i++;
					}
				}
			}
 
			else if(ch == 's') {
				if(i < str.length() - 1) {
					if(str.charAt(i + 1) == '=') {	// s= 일 경우
						i++;
					}
				}
		    }
 
			else if(ch == 'z') {
				if(i < str.length() - 1) {
					if(str.charAt(i + 1) == '=') {	// z= 일 경우
						i++;
					}
				}
			}
		    
			count++;
 
		}
 
		System.out.println(count);
	}
}

1316

import java.util.Scanner;

public class Main {
	
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int count = 0;
		int N = sc.nextInt();//단어의 개수
		
		for(int i =-0; i< N; i++) {
			if(check()== true) {
				count++;
			}
			
		}
		System.out.println(count);
		
	}
	
	public static boolean check() {
		boolean[] ch = new boolean[26];
		int M = 0;
		String str = sc.next();
		
		for(int i=0; i<str.length(); i++) {
			int now = str.charAt(i); // i번째 문자 저장(현재 문자)
			
			//앞선 문자와 i 번째 문자가 같지 않다면?
			if(M != now) {
				
				//해당 문자가 처음 나오는 경우(false인 경우)
				if(ch[now - 'a']== false) {
					ch[now - 'a'] = true; //true로 바꿔준다
					M = now; //다음 턴을 위해 M도 바꿔준다
				}
				
				//해당 문자가 이미 나온 적이 있는 경우(그룹단어가 아니게 됨)
				else {
					return false; //함수 종료
				}
			}
			
			
			//앞선 문자와 i 번쨰 문자가 같다면?(연속된 문자)
			//else 문은 없어도 됨
			else {
				continue;
				
			}
		}
		return true;
	}
}

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN