File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ them with C++ Language.
26
26
| 171 | [ Excel Sheet Column Number] | |
27
27
| 170 | [ Two Sum III - Data structure design] | |
28
28
| 169 | [ Majority Element] | [ C] ( src/169.c ) |
29
- | 168 | [ Excel Sheet Column Title] | |
29
+ | 168 | [ Excel Sheet Column Title] | [ C ] ( src/168.c ) |
30
30
| 167 | [ Two Sum II - Input array is sorted] | |
31
31
| 166 | [ Fraction to Recurring Decimal] | |
32
32
| 165 | [ Compare Version Numbers] | [ C] ( src/165.c ) |
Original file line number Diff line number Diff line change
1
+ #include <stdio.h>
2
+ #include <stdlib.h>
3
+ #include <string.h>
4
+
5
+ char * convertToTitle (int n ) {
6
+ char * ans = (char * )calloc (10 , sizeof (char ));
7
+
8
+ int i ;
9
+ i = 0 ;
10
+ while (n > 0 ) {
11
+ int t = n % 26 ;
12
+ if (t == 0 ) { t = 26 ; ans [i ] = 'Z' ; }
13
+ else { ans [i ] = t + 'A' - 1 ; }
14
+ n -= t ;
15
+ n /= 26 ;
16
+ i ++ ;
17
+ }
18
+ /* reverse string */
19
+ int j = strlen (ans ) - 1 ;
20
+ i = 0 ;
21
+ while (i < j ) {
22
+ char t = ans [i ];
23
+ ans [i ] = ans [j ];
24
+ ans [j ] = t ;
25
+ i ++ ;
26
+ j -- ;
27
+ }
28
+
29
+ return ans ;
30
+ }
31
+
32
+ int main () {
33
+ int n = 26 ;
34
+ printf ("%s\n" , convertToTitle (n ));
35
+ return 0 ;
36
+ }
You can’t perform that action at this time.
0 commit comments