fork(2) download
  1. import sys;
  2.  
  3. S_INIT, S_Q1, S_Q2, S_Q3, S_Q4, S_ERR = 1, 2, 3, 4, 5, 6
  4.  
  5. def odai372():
  6. stat = S_INIT
  7.  
  8. while True:
  9. ch = sys.stdin.read(1)
  10.  
  11. if stat == S_INIT:
  12. buf = ''
  13.  
  14. if ch == '': return
  15. elif ch == "'": stat = S_Q1
  16. elif ch == '"': stat = S_Q3
  17. else: pass
  18.  
  19. elif stat == S_Q1:
  20. if ch == "'":
  21. print('「{}」'.format(buf))
  22. stat = S_INIT
  23. elif ch == '\\': stat = S_Q2
  24. elif ch == '': stat = S_ERR
  25. else: buf += ch
  26.  
  27. elif stat == S_Q2:
  28. if ch == '': stat = S_ERR
  29. else:
  30. buf += ch
  31. stat = S_Q1
  32.  
  33. elif stat == S_Q3:
  34. if ch == '"':
  35. print('「{}」'.format(buf))
  36. stat = S_INIT
  37. elif ch == '\\': stat = S_Q4
  38. elif ch == '': stat = S_ERR
  39. else: buf += ch
  40.  
  41. elif stat == S_Q4:
  42. if ch == '': stat = S_ERR
  43. else:
  44. buf += ch
  45. stat = S_Q3
  46.  
  47. else: # S_ERR
  48. print('input error!')
  49. return
  50.  
  51. odai372()
  52.  
Success #stdin #stdout 0s 7696KB
stdin
var str1="あ'い'う"; 
var str2="あ\"い\"う"; 
var str3 = '彼は"今日は
良い天気ですねぇ"と言った';;;
var str4= 'それはそうと'; var str5 = "同じ行"
var str6='var str7="hogehoge"';
stdout
「あ'い'う」
「あ"い"う」
「彼は"今日は
良い天気ですねぇ"と言った」
「それはそうと」
「同じ行」
「var str7="hogehoge"」