diff --git a/daily/May3.cpp b/daily/May3.cpp new file mode 100644 index 0000000..cafa970 --- /dev/null +++ b/daily/May3.cpp @@ -0,0 +1,15 @@ +#include +using namespace std; + +class Solution { + public: + double average(vector& salary) { + sort(salary.begin(), salary.end()); + int len = salary.size(); + double res = 0; + for (int i = 1; i < len - 1; i++) { + res += salary[i]; + } + return res / (len - 2); + } +}; \ No newline at end of file diff --git a/daily/May5.cpp b/daily/May5.cpp new file mode 100644 index 0000000..69912dc --- /dev/null +++ b/daily/May5.cpp @@ -0,0 +1,61 @@ +#include +using namespace std; + +class Solution { + public: + vector decrypt(vector& code, int k) { + int len = code.size(); + vector ans(len, 0); + if (k == 0) { + return ans; + } + + for (int i = 0; i < len; i++) { + if (k > 0) { + int tmp = k; + while (tmp > 0) { + ans[i] += code[(i + tmp) % len]; + tmp--; + } + } + + if (k < 0) { + int tmp = k; + while (tmp < 0) { + ans[i] += code[(i + tmp + len) % len]; + tmp++; + } + } + } + + return ans; + } +}; + +class Contest396 { + public: + bool isValid(string word) { + if (word.size() < 3) return false; + + bool vowel = false; + bool non_vowel = false; + for (char c : word) { + if (!((c - '0' >= 0 && c - '0' <= 9) || (c - 'a' >= 0 && c - 'a' < 26) || + (c - 'A' >= 0 && c - 'A' < 26))) { + return false; + } + + if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || + c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') { + vowel = true; + } else if ((c - 'a' >= 0 && c - 'a' < 26) || + (c - 'A' >= 0 && c - 'A' < 26)) { + non_vowel = true; + } + } + if (vowel && non_vowel) { + return true; + } + return false; + } +}; \ No newline at end of file