TopCoder SRM 537 Match 250 PROBLEM King Dengklek is the perfect king of Kingdom of Ducks, where slimes and ducks live together in peace and harmony. After several years of waiting, King Dengklek and the queen finally had a baby. Now he is looking for a name for the newborn baby. According to the private rule of Kingdom of Ducks, the name of each member of the royal family must be such that:
SO I HAVE WRITTEN A SIMPLE CODE FOR THIS #include<iostream> #include<vector> #include<stdio.h> #include<stdlib.h> #include<queue> #include<list> #define show(x) copy(x.begin(),x.end(),output) #include<iterator> #define sort(x) sort(x.begin(),x.end()) #include<string> #define vs vector<string> #define vi vector<int> #define pb push_back #include<map> #include<algorithm> #include<sstream> #include<stack> #include<cmath> #include<cstring> #include<iomanip> #include<cctype> using namespace std; class KingXNewBaby { public: string isValid (string name) { int v = 0; if(name.size() != 8 ) { return "NO"; } for(int i = 0 ; i < name.size() ; i++) { if( (name[i] == 'a') || (name[i] == 'e') || (name[i] == 'i') || (name[i] == 'o') || (name[i] == 'u') || (name[i] == 'e' )) { v++; } } if( v == 2) { return "YES"; } else { return "NO"; } return 0; } }; For example, "dengklek" is a valid name because it consists of exactly eight letters: six consonants and two identical vowels, 'e'. You are given a String name. Please help the kingdom determine whether name is valid. Return "YES" if it is a valid name for King Dengklek's newborn baby, or "NO" otherwise. |
Simple and Concise Solution of Most Commonly asked Data Structure And Algorithm Questions in Interviews in Java
Saturday, 17 March 2012
TopCoder SRM 537 Match
Subscribe to:
Posts (Atom)