class Solution {
public:
int averageValue(vector<int>& nums) {
int sum = 0;
int num = 0;
for(int d : nums){
if(d % 6 == 0){
sum += d;
num++;
}
}
if(num == 0) return 0;
return sum / num;
}
};
B
class Solution {
public:
vector<vector<string>> mostPopularCreator(vector<string>& creators, vector<string>& ids, vector<int>& views) {
map<string, long long> map;
unordered_map<string, vector<pair<string, int>>> m;
vector<pair<string, long long>> vecM;
for(int i = 0; i < ids.size(); ++i){
map[creators[i]] += views[i];
m[creators[i]].push_back({ids[i], views[i]});
}
for(auto d : map){
vecM.push_back({d.first, d.second});
}
sort(vecM.begin(), vecM.end(), [](pair<string, long long>& p, pair<string, long long>& q){
return p.second > q.second;
});
vector<vector<string>> ans;
long long max = (*vecM.begin()).second;
for(auto d : vecM){
if(d.second == max){
sort(m[d.first].begin(), m[d.first].end(), [](pair<string, int>& p, pair<string, int>& q){
if(p.second == q.second) return p.first < q.first;
return p.second > q.second;
});
vector<string> temp;
temp.push_back(d.first);
temp.push_back((*m[d.first].begin()).first);
ans.push_back(temp);
}else{
break;
}
}
return ans;
}
};
C
class Solution {
public:
bool judge(long long n, int target){
cout << n <<endl;
int sum = 0;
while(n != 0){
sum += n % 10;
n /= 10;
}
return sum <= target;
}
long long makeIntegerBeautiful(long long n, int target) {
if(judge(n, target)) return 0;
long long ans = 0;
long long t = n;
long long sum = 0;
int time = 0;
while(t != 0){
sum = t % 10 * pow(10, time) + sum;
time++;
t /= 10;
cout << sum <<" ";
if(judge(n + pow(10, time) - sum, target)){
return pow(10, time) - sum;
}
}
return ans;
}
};