Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.lang.*;
- public class Solution{
- BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
- PrintWriter out =new PrintWriter(System.out);
- StringTokenizer st =new StringTokenizer("");
- String next(){
- if(!st.hasMoreTokens()){
- try{
- st=new StringTokenizer(br.readLine());
- }
- catch(Exception e){
- }
- }
- return st.nextToken();
- }
- int nextInt(){
- return Integer.parseInt(next());
- }
- public static void main(String[] args) {
- new Solution().solve();
- }
- void solve(){
- int t=nextInt();
- int count=0;
- while(t-->0){
- count++;
- char arr[]=next().toCharArray();
- String kick="KICK",start="START";
- long res=0,k=0;
- for(int i=0;i<arr.length;){
- if(arr[i]=='K'){
- int j=0;
- while(j<4 && arr[i+j]==kick.charAt(j)){
- j++;
- }
- if(j==4){
- k++;
- }
- i=i+j;
- continue;
- }
- if(arr[i]=='S'){
- int j=0;
- while(j<5 && arr[i+j]==start.charAt(j)){
- j++;
- }
- if(j==5){
- res+=k;
- }
- i=i+j;
- continue;
- }
- i++;
- }
- out.println("Case #"+count+": "+res);
- }
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement