結果
| 問題 |
No.342 一番ワロタww
|
| コンテスト | |
| ユーザー |
threepipes_s
|
| 提出日時 | 2016-02-27 07:58:20 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 96 ms / 5,000 ms |
| コード長 | 3,965 bytes |
| コンパイル時間 | 2,985 ms |
| コンパイル使用メモリ | 86,268 KB |
| 実行使用メモリ | 40,084 KB |
| 最終ジャッジ日時 | 2024-10-15 13:21:51 |
| 合計ジャッジ時間 | 5,226 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Queue;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws NumberFormatException,
IOException {Solve solve = new Solve();solve.solve();}
}
class Solve{
void dump(int[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();}
void dump(int[]a,int n){for(int i=0;i<a.length;i++)System.out.printf("%"+n+"d",a[i]);System.out.println();}
void dump(long[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]+" ");System.out.println();}
void dump(char[]a){for(int i=0;i<a.length;i++)System.out.print(a[i]);System.out.println();}
String itob(int a,int l){return String.format("%"+l+"s",Integer.toBinaryString(a)).replace(' ','0');}
void solve() throws NumberFormatException, IOException{
final ContestScanner in = new ContestScanner();
Writer out = new Writer();
String origin = in.readLine();
while(origin.length()>0 && origin.charAt(0)=='w') origin = origin.substring(1);
char[] str = origin.toCharArray();
char[] s = new char[str.length];
for(int i=0; i<s.length; i++){
s[i] = str[s.length-1-i];
}
int cnt = 0;
int max = 0;
for(int i=0; i<s.length; i++){
if(s[i] == 'w'){
cnt++;
}else cnt = 0;
max = Math.max(max, cnt);
}
if(max==0){
System.out.println();
return;
}
List<String> list = new ArrayList<>();
boolean set = false;
cnt = 0;
String tmp = "";
for(int i=0; i<s.length; i++){
if(s[i] == 'w'){
set = false;
cnt++;
}else{
if(set) tmp = s[i]+tmp;
if(cnt==max){
if(tmp.length()>0) list.add(tmp);
set = true;
tmp = s[i]+"";
}
cnt = 0;
}
max = Math.max(max, cnt);
}
if(tmp.length()>0) list.add(tmp);
Collections.reverse(list);
list.stream().forEach(System.out::println);
}
}
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);}
public void sub(T key)
{final int v=get(key);if(v==1)remove(key);else put(key,v-1);}
}
class Timer{
long time;
public void set(){time=System.currentTimeMillis();}
public long stop(){return time=System.currentTimeMillis()-time;}
public void print()
{System.out.println("Time: "+(System.currentTimeMillis()-time)+"ms");}
@Override public String toString(){return"Time: "+time+"ms";}
}
class Writer extends PrintWriter{
public Writer(String filename)throws IOException
{super(new BufferedWriter(new FileWriter(filename)));}
public Writer()throws IOException{super(System.out);}
}
class ContestScanner {
private InputStreamReader in;private int c=-2;
public ContestScanner()throws IOException
{in=new InputStreamReader(System.in);}
public ContestScanner(String filename)throws IOException
{in=new InputStreamReader(new FileInputStream(filename));}
public String nextToken()throws IOException {
StringBuilder sb=new StringBuilder();
while((c=in.read())!=-1&&Character.isWhitespace(c));
while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
return sb.toString();
}
public String readLine()throws IOException{
StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
return sb.toString();
}
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());}
}
threepipes_s