https://www.spoj.com/problems/ADFRUITS/
の問題を解いていたのですが、テストケースや自分で考えた落とし穴ケースは全てあっているのにWAになります...
#作ったコード
python
1def exists(a, b): #文字列bがバラバラにaに入ってたらTrue 2 pos = 0 3 for ch in a: 4 if pos < len(b) and ch == b[pos]: 5 pos += 1 6 return pos == len(b) 7 8word = [] 9dif = [] 10try: 11 while True: 12 a, b = input().split() 13 word.append([a, b]) 14except EOFError: 15 pass 16 17for i in range(len(word)): 18 s1 = word[i][0] 19 s2 = word[i][1] 20 s3 = s1 + s2 21 s4 = s2 + s1 22 #s5 = s3[1:-1] 23 #s6 = s4[1:-1] 24 25 if(s1 == s2 and len(s1) == 1): 26 print(s1) 27 else: 28 for c in 'abcdefghijklmnopqrstuvwxyz': 29 if(min(s1.count(c), s2.count(c)) > 0): 30 dif.append(c) 31 for j in range(len(dif)): #s1→s2 32 start = 0 33 cnt = s3.count(dif[j]) 34 for k in range(cnt): 35 num = s3.find(dif[j], start, len(s3)) 36 s7 = s3[:num] + s3[num+1:] 37 if(exists(s7, s1) and exists(s7, s2)): 38 s3 = s7 39 start = num 40 else: 41 start = num+1 42 for j in range(len(dif)): 43 start = 0 44 cnt = s4.count(dif[j]) 45 for k in range(cnt): 46 num = s4.find(dif[j], start, len(s4)) 47 s7 = s4[:num] + s4[num+1:] 48 if(exists(s7, s1) and exists(s7, s2)): 49 s4 = s7 50 start = num 51 else: 52 start = num+1 53 54 a = len(s3) 55 b = len(s4) 56 if(a > b): 57 print(s4) 58 else: 59 print(s3) 60 dif.clear()
#試したテストケースとその出力
##入力
apple peach ananas banana pear peach a a aa aa aa ai aaai iiaa aiueo iueoa aio aou aoa oao aoa aoo
##出力
appleach bananas pearch a aa aai iiaaai aiueoa aiou aoao aoao
何を考え忘れているか、またここはこうしたほうがいい等ありましたらご教授ください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/06/13 23:59
2019/06/14 00:01
2019/06/14 00:25 編集
2019/06/14 00:49
2019/06/14 07:41