Skip to content

Commit

Permalink
update: May3 and May5
Browse files Browse the repository at this point in the history
  • Loading branch information
aucker committed May 5, 2024
1 parent fa97174 commit 4fc3d17
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
15 changes: 15 additions & 0 deletions daily/May3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
double average(vector<int>& 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);
}
};
61 changes: 61 additions & 0 deletions daily/May5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
vector<int> decrypt(vector<int>& code, int k) {
int len = code.size();
vector<int> 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;
}
};

0 comments on commit 4fc3d17

Please sign in to comment.