Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> Python

विपर्यय शब्दों के सबसे बड़े उपसमुच्चय का आकार खोजने के लिए पायथन कार्यक्रम

लोअरकेस सरणी को देखते हुए। हमारा कार्य स्ट्रिंग के सबसे बड़े उपसमुच्चय का आकार ज्ञात करना है जो एक दूसरे का विपर्ययण है। स्ट्रिंग के विपर्यय का अर्थ है कि एक स्ट्रिंग दूसरे का विपर्यय है यदि दूसरा केवल पहले की पुनर्व्यवस्था है। यहां हम काउंटर () पद्धति का उपयोग करके अजगर में इस समस्या को जल्दी से हल कर सकते हैं।

उदाहरण के लिए, स्ट्रिंग्स 'पायथन' और 'टाइफॉन' विपर्ययण हैं।

एल्गोरिदम

Step 1: Split input string separated by space into words.
Step 2: sort each string in given list of strings
Step 3: now create a dictionary using a counter method which will have strings as key and their Frequencies as value.
Step 4: get maximum value of frequency using max function.

उदाहरण कोड

# Function to find the size of largest subset 
# of anagram words from collections import Counter
def largestana(str1):
   # split input string separated by space
   str1 = str1.split(" ")
   # sort each string in given list of strings
   for i in range(0,len(str1)):
      str1[i]=''.join(sorted(str1[i]))
   # now create a dictionary using the counter method
   # which will have strings as key and their
   # frequencies as the value
   newstr1 = Counter(str1)
   # get maximum value of frequency
   print ("The Size Of largest subset of Anangram word is ::>",max(newstr1.values()))
   # Driver program
   if __name__ == "__main__":
      str1 = input("Enter the string ::>")
      largestana(str1)

आउटपुट

Enter the string ::>qwe ewq rty ytr ytr ytr
The Size Of largest subset of Anangram word is ::> 4

  1. ग्राफ़ में सबसे बड़े गुट के न्यूनतम आकार का पता लगाने का कार्यक्रम (पायथन)

    मान लीजिए कि हमें एक ग्राफ दिया गया है और ग्राफ में सबसे बड़े समूह का न्यूनतम आकार ज्ञात करने के लिए कहा गया है। ग्राफ़ का एक समूह एक ग्राफ़ का एक उपसमुच्चय होता है, जहाँ प्रत्येक शीर्ष जोड़े आसन्न होते हैं, अर्थात प्रत्येक जोड़े के बीच एक किनारा मौजूद होता है। एक ग्राफ में सबसे बड़ा गुट ढूँढना बहुप

  1. एक सरणी में सबसे बड़ा तत्व खोजने के लिए पायथन प्रोग्राम

    इस लेख में, हम नीचे दिए गए समस्या कथन के समाधान के बारे में जानेंगे। समस्या कथन - हमें एक सरणी दी गई है, हमें सरणी के सबसे बड़े तत्व की गणना करने की आवश्यकता है। यहां हम ब्रूटफोर्स दृष्टिकोण का उपयोग करते हैं जिसमें हम पूरे लूप को पार करके सबसे बड़े तत्व की गणना करते हैं और तत्व प्राप्त करते हैं।

  1. किसी दिए गए स्ट्रिंग के बाइनरी प्रतिनिधित्व में लगातार 1 की सबसे बड़ी लंबाई खोजने के लिए पायथन प्रोग्राम।

    संख्या को देखते हुए, इसके द्विआधारी प्रतिनिधित्व में सबसे लंबे समय तक लगातार 1 की लंबाई पाएं। उदाहरण Input: n = 15 Output: 4 The binary representation of 14 is 1111. एल्गोरिदम Step 1: input the number. Step 2: use one counter variable c=0. Step 3: Count the number of iterations to reach i = 0. St