250
class RosePetals {
public:
int getScore(vector <int> d) {
int r = 0;
int p[] = {-9999, 0, 0, 2, 0, 4, 0};
for(int i=0; i<d.size(); ++i){
r += p[d[i]];
}
return r;
}
};
500
class DigitsSum {
public:
int lastDigit(int n) {
char buff[100];
while(true){
sprintf(buff, "%d", n);
string s(buff);
if(s.size() == 1)break;
n = 0;
for(int i=0; i<s.size(); ++i){
n += s[i] - '0';
}
}
return n;
}
};
900
class KidsGame {
public:
int kthKid(int n, int m, int k) {
int r = 0;
int idx = (m - 1) % n + 1;
while(idx != k){
if(idx < k)--k;
++r;
--n;
idx = (idx - 1 + n + m - 1) % n + 1;
}
return r + 1;
}
};
0 件のコメント :
コメントを投稿