Submission #533059
Source Code Expand
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.Random; public class Main{ public static void main(String[] args){ try {(new Solve()).solve();} catch (NumberFormatException | IOException e) {e.printStackTrace();} } } class Solve{ void solve() throws NumberFormatException, IOException{ final ContestScanner in = new ContestScanner(); int t = in.nextInt(); char[] tk = "tokyo".toCharArray(); char[] kt = "kyoto".toCharArray(); for(int i=0; i<t; i++){ int count = 0; char[] s = in.nextToken().toCharArray(); int j; for(j=0; j<s.length-4; j++){ if(check(s, j, tk) || check(s, j, kt)){ count++; j += 4; } } System.out.println(count); } } boolean check(char[] s, int idx, char[] t){ for(int i=0; i<t.length; i++){ if(s[idx+i]!=t[i]) return false; } return true; } } class MultiSet<T> extends HashMap<T, Integer>{ @Override public Integer get(Object key){return containsKey(key)?super.get(key):0;} public void add(T key,int v){put(key,get(key)+v);} public void add(T key){put(key,get(key)+1);} } class ContestWriter{ private PrintWriter out; public ContestWriter(String filename) throws IOException {out = new PrintWriter(new BufferedWriter(new FileWriter(filename)));} public ContestWriter() throws IOException{out = new PrintWriter(System.out);} public void println(String str){out.println(str);} public void print(String str){out.print(str);} public void close(){out.close();} } class ContestScanner { private BufferedReader reader; private String[] line; private int idx; public ContestScanner()throws FileNotFoundException {reader=new BufferedReader(new InputStreamReader(System.in));} public ContestScanner(String filename)throws FileNotFoundException {reader=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));} public String nextToken()throws IOException{if(line==null||line.length<=idx){ line=reader.readLine().trim().split(" ");idx=0;}return line[idx++];} public String readLine()throws IOException{return reader.readLine();} public long nextLong()throws IOException,NumberFormatException{return Long.parseLong(nextToken());} public int nextInt()throws NumberFormatException,IOException{return(int)nextLong();} public double nextDouble()throws NumberFormatException,IOException {return Double.parseDouble(nextToken());} }
Submission Info
Submission Time | |
---|---|
Task | A - 東京都 |
User | threepipes_s |
Language | Java (OpenJDK 1.7.0) |
Score | 100 |
Code Size | 2698 Byte |
Status | AC |
Exec Time | 394 ms |
Memory | 24160 KB |
Judge Result
Set Name | All | ||
---|---|---|---|
Score / Max Score | 100 / 100 | ||
Status |
|
Set Name | Test Cases |
---|---|
All | 10_random_to_kyo.txt, 20_noised_tokyoto.txt, 99_teuchi.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
10_random_to_kyo.txt | AC | 391 ms | 23496 KB |
20_noised_tokyoto.txt | AC | 394 ms | 24160 KB |
99_teuchi.txt | AC | 373 ms | 22816 KB |