Notice
Recent Posts
문제 풀이 및 개발 공간
[백준] 16139번 인간-컴퓨터 상호작용 (silver 1 본문
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
String a=br.readLine();
int[][] num=new int[26][a.length()+1];
int q=Integer.valueOf(br.readLine());
int end=a.length();
for(int i=1; i<end+1; i++){
int temp=a.charAt(i-1)-'a';
for(int j=0; j<26; j++){
if(j==temp){
num[temp][i]=num[temp][i-1]+1;
}
else{
num[j][i]=num[j][i-1];
}
}
}
for(int i=0; i<q; i++){
st=new StringTokenizer(br.readLine());
int find= st.nextToken().charAt(0)-'a';
int start=Integer.valueOf(st.nextToken());
int fin=Integer.valueOf(st.nextToken());
bw.write(num[find][fin+1]-num[find][start]+"\n");
}
bw.flush();
}
}
'백준공부 > java' 카테고리의 다른 글
[백준] 4413번 CDVII (gold 5 (0) | 2023.10.12 |
---|---|
[백준] 14908번 구두 수선공 (gold 1 (0) | 2023.10.12 |
[백준] 2444번 별 찍기 -7 (bronze 3 (0) | 2023.10.09 |
[백준] 11728번 배열 합치기 (silver 5 (0) | 2023.10.09 |
[백준] 9465번 스티커 (silver 1 (2) | 2023.10.09 |