Short Problem Definition:
That’s the value of pi! (Ignoring the floating point) A song is a pi song if the length of its words represent the value of pi.
time complexity is O(N*T)
space complexity is O(N)
This problem is straight forward.
#!/usr/bin/py PI = map(int, list("31415926535897932384626433833")) def isPiSong(s): for idx, word in enumerate(s): if len(word) != PI[idx]: return False return True if __name__ == '__main__': t = input() for _ in range(t): s = raw_input().split() if isPiSong(s): print "It's a pi song." else: print "It's not a pi song."
If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.