๐Ÿ”ฅ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๊ฐœ์˜ ๋Œ“๊ธ€