मान लीजिए, हमें एक सरणी 'input' में n स्ट्रिंग्स दी गई हैं। स्ट्रिंग्स नाम हैं, हमें यह पता लगाना है कि वे पुरुष या महिला नाम हैं। यदि कोई नाम 'a', 'e', 'i', या 'y' से समाप्त होता है; तो यह कहा जा सकता है कि यह एक महिला नाम है। हम स्ट्रिंग में प्रत्येक इनपुट के लिए 'male' या 'female' प्रिंट करते हैं।
उदाहरण के लिए, यदि इनपुट n = 5, input = {"Lily", "Rajib", "Thomas", "Riley", "Chloe"} है, तो आउटपुट Female, Male, Male, Female, Female होगा।
चरण
इसे हल करने के लिए, हम निम्नलिखित चरणों का पालन करेंगे:
for initialize i := 0, when i < n, update (increase i by 1), do: s := input[i] l := size of s if s[l - 1] is same as 'a' or s[l - 1] is same as 'e' or s[l - 1] is same as 'i' or s[l - 1] is same as 'y', then: print("Female") Otherwise, print("Male")उदाहरण
बेहतर समझ के लिए निम्नलिखित कार्यान्वयन देखें:
#includeusing namespace std; #define N 100 void solve(int n, string input[]) { for(int i = 0; i < n; i++) { string s = input[i]; int l = s.size(); if (s[l - 1] == 'a' || s[l - 1] == 'e' || s[l - 1] == 'i' || s[l - 1] == 'y') cout<< "Female" << endl; else cout << "Male" << endl; } } int main() { int n = 5; string input[] = {"Lily", "Rajib", "Thomas", "Riley", "Chloe"}; solve(n, input); return 0; }
इनपुट
5, {"Lily", "Rajib", "Thomas", "Riley", "Chloe"}आउटपुट
Female Male Male Female Female