[java] 백준 단계별로 풀어보기 7단계 (2)알고리즘/백준2021. 7. 2. 20:16
Table of Contents
4단계 2675번 문자열 반복
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
String s;
for(int i=0; i<t; i++){
int r = sc.nextInt();
s = sc.next();
for(int j=0; j<s.length(); j++){
for(int k=0; k<r; k++){
// 입력받은 문자열을 문자 하나하나로 쪼갬.
System.out.print(s.charAt(j));
}
}
System.out.println();
}
}
}
5단계 1157번 단어 공부
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// 입력받을때 다 대문자로 바꿔줌
String s = sc.next().toUpperCase();
int[] count = new int[26];
int max = 0;
char c = '?';
for(int i=0; i<s.length(); i++){
count[s.charAt(i)-'A']++;
}
for(int i=0; i<count.length; i++){
if(count[i] > max){
max = count[i];
c = (char) (i+'A');
}else if(count[i] == max){
c = '?';
}
}
System.out.print(c);
}
}
6단계 1152번 단어의 개수
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// 입력받은 문자열을 공백을 기준으로 나눔
StringTokenizer st = new StringTokenizer(br.readLine()," ");
// 토큰의 개수 확인,
System.out.println(st.countTokens());
// Scanner sc = new Scanner(System.in);
//
// String s = sc.nextLine().trim();
// int count = 1;
// char[] c = new char[s.length()];
// for (int i = 0; i < s.length(); i++) {
// c[i] = s.charAt(i);
//
// if (c[i] == ' ') {
// count+=1;
// }
// }
//
// System.out.println(count);
}
}
'알고리즘 > 백준' 카테고리의 다른 글
[java] 백준 2941번 크로아티아 알파벳 (0) | 2021.07.06 |
---|---|
[java] 백준 단계별로 풀어보기 7단계 (3) (0) | 2021.07.05 |
[java] 백준 단계별로 풀어보기 7단계 (1) (0) | 2021.07.01 |
[java] 백준 단계별로 풀어보기 6단계 (0) | 2021.06.30 |
[java] 백준 단계별로 풀어보기 5단계 (2) (0) | 2021.06.29 |
@펄찌 :: Pearl's Story
펄의 일상이 궁금한 사람 요기~
즐거운 하루 되셨으면 좋겠습니다😊