fork download
  1. //05.10.2008 - 16:22:47
  2. //12.09.2008 - 22:10:03
  3. import java.lang.*;
  4. import java.math.BigInteger;
  5. import java.io.*;
  6. import java.util.*;
  7. import java.awt.geom.*;
  8.  
  9. public class Solution implements Runnable {
  10. public static BufferedReader br;
  11. public static PrintWriter out;
  12. public static StringTokenizer stk;
  13. public static boolean isStream = true;
  14.  
  15. public static void main(String[] args) throws IOException {
  16. if (isStream) {
  17. } else {
  18. br = new BufferedReader(new FileReader("in.txt"));
  19. }
  20. out = new PrintWriter(System.out);
  21. new Thread(new Solution()).start();
  22. }
  23.  
  24. public void loadLine() {
  25. try {
  26. stk = new StringTokenizer(br.readLine());
  27. } catch (IOException e) {
  28. e.printStackTrace();
  29. }
  30. }
  31.  
  32. public String nextLine() {
  33. try {
  34. return br.readLine();
  35.  
  36. } catch (IOException e) {
  37. e.printStackTrace();
  38. return "";
  39. }
  40. }
  41.  
  42. public String nextWord() {
  43. while (stk == null || !stk.hasMoreTokens())
  44. loadLine();
  45. return stk.nextToken();
  46. }
  47.  
  48. public Integer nextInt() {
  49. while (stk == null || !stk.hasMoreTokens())
  50. loadLine();
  51. return Integer.parseInt(stk.nextToken());
  52. }
  53.  
  54. public Long nextLong() {
  55. while (stk == null || !stk.hasMoreTokens())
  56. loadLine();
  57. return Long.valueOf(stk.nextToken());
  58. }
  59.  
  60. public Double nextDouble() {
  61. while (stk == null || !stk.hasMoreTokens())
  62. loadLine();
  63. String s = stk.nextToken();
  64. if (s.charAt(0) == '.')
  65. s = '.' + s;
  66. return Double.valueOf(s);
  67. }
  68.  
  69. public Float nextFloat() {
  70. while (stk == null || !stk.hasMoreTokens())
  71. loadLine();
  72. return Float.valueOf(stk.nextToken());
  73. }
  74.  
  75. String get(int a) {
  76. StringBuilder sb = new StringBuilder();
  77. if (a %2 == 0) {
  78. for (int i = 0; i < a/2; i++) {
  79. sb.append(" --");
  80. }
  81. } else {
  82. sb.append(" ---"); a-=3;
  83. for (int i = 0; i < a/2; i++) {
  84. sb.append(" --");
  85. }
  86. }
  87. return sb.toString() + " ";
  88. }
  89.  
  90. public void run() {
  91. int n = nextInt();
  92. for (int j = 0; j < n; j++) {
  93. String s = nextLine();
  94. s = s.replaceAll("[ ]+", " ");
  95. s = s.replaceAll(" -", "-");
  96. s = s.replaceAll("- ", "-");
  97. s = s.replaceAll(" \"", "\"");
  98. s = s.replaceAll("\" ", "\"");
  99. int cnt = 0;
  100. StringBuilder ans = new StringBuilder();
  101. for (int i = 0; i < s.length(); i++) {
  102. if (s.charAt(i) == '-') {
  103. cnt++;
  104. } else {
  105. if (cnt == 1) {
  106. if (s.charAt(i) == '"' || s.charAt(i-2) == '"') {
  107. ans = new StringBuilder("error");
  108. break;
  109. } else {
  110. ans.append('-');
  111. }
  112. } else
  113. if (cnt == 2) {
  114. ans.append(" -- ");
  115. } else
  116. if (cnt >= 3) ans.append(get(cnt));
  117. cnt = 0;
  118. ans.append(s.charAt(i));
  119. }
  120. }
  121. out.println(ans.toString());
  122. }
  123. out.flush();
  124. }
  125. }
  126.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty