Advertisement
Guest User

qt

a guest
Oct 18th, 2020
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.lang.*;
  4. public class Solution{
  5. BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
  6. PrintWriter out =new PrintWriter(System.out);
  7. StringTokenizer st =new StringTokenizer("");
  8. String next(){
  9. if(!st.hasMoreTokens()){
  10. try{
  11. st=new StringTokenizer(br.readLine());
  12. }
  13. catch(Exception e){
  14.  
  15. }
  16. }
  17. return st.nextToken();
  18. }
  19. int nextInt(){
  20. return Integer.parseInt(next());
  21. }
  22. public static void main(String[] args) {
  23. new Solution().solve();
  24. }
  25. void solve(){
  26. int t=nextInt();
  27. int count=0;
  28. while(t-->0){
  29. count++;
  30. char arr[]=next().toCharArray();
  31. String kick="KICK",start="START";
  32. long res=0,k=0;
  33. for(int i=0;i<arr.length;){
  34. if(arr[i]=='K'){
  35. int j=0;
  36. while(j<4 && arr[i+j]==kick.charAt(j)){
  37. j++;
  38. }
  39. if(j==4){
  40. k++;
  41. }
  42. i=i+j;
  43. continue;
  44. }
  45. if(arr[i]=='S'){
  46. int j=0;
  47. while(j<5 && arr[i+j]==start.charAt(j)){
  48. j++;
  49. }
  50. if(j==5){
  51. res+=k;
  52. }
  53. i=i+j;
  54. continue;
  55. }
  56. i++;
  57. }
  58. out.println("Case #"+count+": "+res);
  59. }
  60. out.close();
  61. }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement