-
-
Save toanalien/1b7a17e1067061572a26 to your computer and use it in GitHub Desktop.
Letter Combinations of a Phone Number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
/** | |
* Return an array of size *returnSize. | |
* Note: The returned array must be malloced, assume caller calls free(). | |
*/ | |
int slip_num(int num) | |
{ | |
int temp = 0; | |
while (num/10!=0) | |
{ | |
temp+=num%10; | |
temp*=10; | |
num = num/10; | |
} | |
temp+=num; | |
return temp; | |
} | |
void Try(int num) | |
{ | |
int letter [] = {97,100,103,106,109, 112,116,119}; | |
int temp = num%10; | |
temp-=2; | |
char *result; | |
char buffer [33]; | |
//printf("%d", letter[2]); | |
for (int i = 0; i<letter[temp+1]- letter[temp]; i++) | |
{ | |
printf("%c", letter[temp]+i); | |
//strcat(result, itoa(letter[temp]+i,buffer, 10)); | |
if(num/10!=0) | |
Try(num/10); | |
else | |
printf("\n"); | |
} | |
} | |
void letterCombinations(int digits, int* returnSize=0) { | |
//char letter[8][4] = {('a', 'b', 'c'), ('d','e','f'), ('g','h','i'),('j','k','l'), ('m','n','o'), ('p', 'q', 'r', 's'), ('t','u','v'), ('w','x', 'y','z')}; | |
int i =1, temp; | |
temp = digits; | |
//char **result; | |
/* | |
while (temp/10!=0) | |
{ | |
i++; | |
temp /=10; | |
} | |
*/ | |
} | |
int main() | |
{ | |
char digits[] = "\"23\""; | |
char *pch; | |
pch = digits+1; | |
strncpy(pch, digits+1,strlen(digits+1)-1); | |
pch[strlen(pch) ] = '\0'; | |
int num = atoi(pch); | |
//printf("%d", num); | |
//letterCombinations(num); | |
//printf("%d", slip_num(1)); | |
num = slip_num(num); | |
Try(num); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment