728x90
반응형
Solution
- Use ASCII transformation lower case english letter to integer
#include <math.h>
int GetNumericValue(char* ArrWord);
bool isSumEqual(char* firstWord, char* secondWord, char* targetWord) {
bool RetVal = true;
int fisrtWordNumericValue = GetNumericValue(firstWord);
int secondWordNumericValue = GetNumericValue(secondWord);
int targetWordNumericValue = GetNumericValue(targetWord);
if (targetWordNumericValue == (fisrtWordNumericValue + secondWordNumericValue))
{
RetVal = true;
}
else
{
RetVal = false;
}
return RetVal;
}
int GetNumericValue(char* ArrWord)
{
int ArrIntWord[8] = { 0 };
int LengthOfWord = 0;
int Num = 0;
int Unit = 1;
while (ArrWord[LengthOfWord] != '\0')
{
ArrIntWord[LengthOfWord] = ArrWord[LengthOfWord] - 97;
++LengthOfWord;
}
Num = ArrIntWord[LengthOfWord - 1];
for (int i = (LengthOfWord - 2); i > -1; --i)
{
Num += ArrIntWord[i] * (int)pow(10, Unit);
++Unit;
}
return Num;
}
728x90
반응형
'코딩 문제' 카테고리의 다른 글
[Leet Code] 231. Power of Two, C++ (0) | 2023.01.17 |
---|---|
[LeetCode] 2331. Evaluate Boolean Binary Tree, cpp (0) | 2023.01.10 |
[LeetCode] 2406. Divide Intervals Into Minimum Number of Groups, C (0) | 2023.01.02 |
[LeetCode] 1614. Maximum Nesting Depth of the Parenthesesm, C (0) | 2023.01.01 |
[LeetCode] 2283. Check if Number Has Equal Digit Count and Digit Value, C (0) | 2023.01.01 |