File tree Expand file tree Collapse file tree 1 file changed +67
-0
lines changed
LeetCode/Sum_of_Digits_of_String_After_Convert Expand file tree Collapse file tree 1 file changed +67
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments