Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae6c52b

Browse files
solved leetcode daily challenge, Sum_of_Digits_of_String_After_Convert
1 parent 7718f95 commit ae6c52b

File tree

1 file changed

+67
-0
lines changed
  • LeetCode/Sum_of_Digits_of_String_After_Convert

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#include <bits/stdc++.h>
2+
#include <gtest/gtest.h>
3+
using namespace std;
4+
5+
6+
//// START
7+
/*
8+
## Sum of Digits of String After Convert
9+
10+
*/
11+
12+
class Solution {
13+
public:
14+
int getLucky(string s, int k) {
15+
vector<int> nums;
16+
for (char c : s) nums.push_back(c - 'a' + 1);
17+
int ret = 0;
18+
for (auto n : nums) {
19+
while (n > 0) {
20+
ret += n % 10;
21+
n /= 10;
22+
}
23+
}
24+
k--;
25+
while (k > 0) {
26+
int tmp = 0;
27+
while (ret > 0) {
28+
int c = ret % 10;
29+
ret /= 10;
30+
tmp += c;
31+
}
32+
ret = tmp;
33+
k--;
34+
}
35+
return ret;
36+
}
37+
};
38+
39+
//// END
40+
struct T {
41+
42+
};
43+
44+
TEST(Solution, test) {
45+
T ts[] = {
46+
{
47+
48+
},
49+
{
50+
51+
},
52+
53+
};
54+
55+
for (T t : ts) {
56+
Solution solution;
57+
58+
}
59+
}
60+
61+
int main() {
62+
testing::InitGoogleTest();
63+
64+
return RUN_ALL_TESTS();
65+
}
66+
67+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /