समस्या विवरण
एक वाक्यांश दर्शाने वाली स्ट्रिंग s दी गई है, इसका एक्रोनिम बनाएं। एक्रोनिम कैपिटलाइज़्ड होना चाहिए और "and" शब्द को शामिल न करें।
उदाहरण
इनपुट: "Indian Space Research Organisation"
आउटपुट: "ISRO"
एल्गोरिदम
- शब्दों में विभाजित करें:
tokens = s.split() - प्रत्येक शब्द के लिए:
- यदि शब्द "and" नहीं है: पहला अक्षर जोड़ें
- परिणाम को अपरकेस में बदलें
पायथन कार्यान्वयन
class Solution:
def solve(self, s):
tokens = s.split()
string = ""
for word in tokens:
if word.lower() != "and":
string += word[0]
return string.upper()
ob = Solution()
print(ob.solve("Indian Space Research Organisation"))
इनपुट
"Indian Space Research Organisation"
आउटपुट
ISRO
नोट
word.lower() != "and" से केस-इनसेंसिटिव तुलना होती है।