@@ -115,3 +115,5 @@ Alogrithm/Alogrithm/Debug/9_AddBinary.obj | |||||
Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/27a527fda8b54c6b/9_ADDBINARY.ipch | Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/27a527fda8b54c6b/9_ADDBINARY.ipch | ||||
Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/d00489e06883ba57/9_ ADDBINARY.ipch | Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/d00489e06883ba57/9_ ADDBINARY.ipch | ||||
Alogrithm/TestResults/dc42f77d-a2f7-41a9-8b8c-1ee3f1a82eb9/林_MI-1 2021-01-18 14_12_23.coverage | Alogrithm/TestResults/dc42f77d-a2f7-41a9-8b8c-1ee3f1a82eb9/林_MI-1 2021-01-18 14_12_23.coverage | ||||
Alogrithm/.vs/Alogrithm/v16/ipch/AutoPCH/86fa7a487ad3f37c/10_BINARYTREEPATHS.ipch | |||||
Alogrithm/.vs/Alogrithm/v16/TestStore/3/003.testlog |
@@ -18,6 +18,11 @@ output=1 | |||||
array=1,0,3,4,2,1,0,3,4 | array=1,0,3,4,2,1,0,3,4 | ||||
key=3 | key=3 | ||||
output=0 | output=0 | ||||
[Test6] | |||||
array=8,7,15,1,6,1,9,15 | |||||
key=1 | |||||
output=0 | |||||
[Test7] | |||||
array=8,7,15,1,6,1,9,15 | |||||
key=3 | |||||
output=1 |
@@ -18,4 +18,4 @@ Na=52 | |||||
nExpect=AZ | nExpect=AZ | ||||
[Test7] | [Test7] | ||||
Na=53 | Na=53 | ||||
nExpect=AAA | |||||
nExpect=BA |
@@ -1,5 +1,6 @@ | |||||
#pragma once | #pragma once | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <stdlib.h> | |||||
char* ExcelSheetColumnTitle(int n); | char* ExcelSheetColumnTitle(int n); |
@@ -1,20 +1,17 @@ | |||||
#include "../include/2_ExcelSheetColumnTitle.h" | #include "../include/2_ExcelSheetColumnTitle.h" | ||||
#define STR_LEN 100 | |||||
//给定一个整数,返回它在 Excel 表中相对应的列名称,如果在Excel表中找不到该列,则返回""。 | //给定一个整数,返回它在 Excel 表中相对应的列名称,如果在Excel表中找不到该列,则返回""。 | ||||
char* ExcelSheetColumnTitle(int n) | char* ExcelSheetColumnTitle(int n) | ||||
{ | { | ||||
static char str[STR_LEN] = { 0 }; | |||||
int i = 0; | |||||
while (n > 0) { | |||||
if ((n > 0) && (n <= 26)) { | |||||
str[i] = 'A' + n - 1; | |||||
} | |||||
else if (n > 26) { | |||||
str[i] = 'A'; | |||||
} | |||||
n = n - 26; | |||||
i++; | |||||
char* ret = (char*)malloc(sizeof(char) * 10);//开辟一片空间,存需要返回的字符串 | |||||
int i = 9;// | |||||
while (n) | |||||
{ | |||||
n -= 1;//给n减一,因为n后面是从'A'开始的 | |||||
ret[i - 1] = n % 26 + 'A';//从后往前赋值,从最后一个赋值到第一个 | |||||
n /= 26; | |||||
i--;//给下一个赋值 | |||||
} | } | ||||
char* pstr = str; | |||||
return pstr; | |||||
ret[9] = '\0'; | |||||
return ret + i;//去掉前面的前导字符,如果前面没有字符则指针后移 | |||||
} | } |
@@ -45,7 +45,7 @@ namespace UnitTest | |||||
GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2); | GetPrivateProfileString(Section_Name[i], "Na", " ", Na.GetBuffer(20), 20, FileName_2); | ||||
GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2); | GetPrivateProfileString(Section_Name[i], "nExpect", " ", nExpect.GetBuffer(100), 100, FileName_2); | ||||
char* nReal = ExcelSheetColumnTitle(_ttoi(Na)); | char* nReal = ExcelSheetColumnTitle(_ttoi(Na)); | ||||
Assert::AreEqual(*nReal, *nExpect); | |||||
Assert::AreEqual(nReal, nExpect); | |||||
} | } | ||||
} | } | ||||
}; | }; | ||||