def is_sublime(str1, str2)
str1.each_char do |s|
unless str2.include?(s)
return false
end
end
return true
end
def run
str1,str2 = STDIN.gets.rstrip.split
if is_sublime(str1,str2)
puts "sublime"
else
puts "unsublime"
end
end
STDIN.gets.to_i.times { run }
でもPythonのシンプルさには劣るな…
import sys
def isSublime(str1,str2):
for c in str1:
if not c in str2:
return False
return True
def run():
str1,str2 = sys.stdin.readline().rstrip().split()
if isSublime(str1, str2):
print "sublime"
else:
print "unsublime"
for i in range(int(sys.stdin.readline())):
run()
Two strings are "sublime" when all the characters in the first string appear in the same order in the second string. For example, "rat" and "rather" are sublime, "mat" and "moat" are sublime, but "can" and "cat" are not. We want to determine whether pairs of strings are sublime or not. The first line of the input will be an integer N (1 <= N <= 100). Each of the following N lines represents a single test case, containing a space-separated pair of strings A, B, each of which consists of only letters (no special characters). For each test case, print 'sublime' if A is sublime to B, or 'unsublime' if not. No blank line between test cases.
Sample Input/Output
4 z izy iy izy ezy izy c c
sublime sublime unsublime sublime
0 件のコメント:
コメントを投稿