実現したいこと
AtCoder335のC - Loong Trackingで6行目のinput()の場合はWAになり、input().split()の場合はACする理由が知りたい。
発生している問題・分からないこと
上のコードは6行目がinput()で7AC,24WAになります。
下のコードは6行目がinput().split()で31ACになります。
該当のソースコード
python
1N, Q = map(int,input().split()) 2q = [] 3for i in range(N, 0,-1): 4 q.append([i, 0]) 5for _ in range(Q): 6 a = input() 7 if a[0] == "1": 8 direction = a[-1] 9 x, y = q[-1] 10 if direction == "R": 11 q.append([x + 1, y]) 12 elif direction == "L": 13 q.append([x - 1, y]) 14 elif direction == "U": 15 q.append([x, y + 1]) 16 else: 17 q.append([x, y - 1]) 18 19 else: 20 idx = int(a[-1]) 21 x, y = q[- idx] 22 print(x, y)
python
1N, Q = map(int,input().split()) 2q = [] 3for i in range(N, 0,-1): 4 q.append([i, 0]) 5 6for _ in range(Q): 7 a = input().split() 8 if a[0] == "1": 9 direction = a[-1] 10 x, y = q[-1] 11 if direction == "R": 12 q.append([x + 1, y]) 13 elif direction == "L": 14 q.append([x - 1, y]) 15 elif direction == "U": 16 q.append([x, y + 1]) 17 else: 18 q.append([x, y - 1]) 19 20 else: 21 idx = int(a[-1]) 22 x, y = q[- idx] 23 print(x, y)
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
ACとWAのコードの違いが6行目にあるのは発見できたが、なぜ違う結果になるのかわからないです。
input()の場合は文字列型、input().split()の場合はリスト型で違うが、そのあとa[0], a[-1]で違い生まれないはずだと思います。
補足
特になし
回答1件
あなたの回答
tips
プレビュー