Re: 工作后第二张工资单,感觉还是很穷啊,大家说说自己的情况 (转载)# Joke - 肚皮舞运动
w*x
1 楼
直接贴Google doc了
Given a word, print out all the combinations of words from the letters that
make it. For example:
bad: abd adb bda dab dba
void _inner_print(char str[], int len, int pos)
{
if (pos == len)
{
cout< return;
}
for (int i = pos; i < len; i++)
{
swap(str[pos], str[i]);
_inner_print(str, len, pos+1);
swap(str[pos], str[i]);
}
}
Input: bad
step 1: 3, i = 0 - bad
step 2.: 3, i = 1 - abd
step 2.: 3, i = 2 - dabchar
void printAllPermutation(const char* str)
{
if (NULL == str || 0 == *str)
return;
int nLen = strlen(str);
char* strTmp = new char[nLen+1];
strcpy(strTmp, str);
_inner_print(strTmp, nLen, 0);
delete [] strTMp;
}
Serialize a list of strings to a file
Input is a file, an array of string pointers and number of elements in the
array. Serialize all the strings in the given file.
bool serializeStrList(const char* strs[], int n, const char* szFileName)
{
if (NULL == strs || n <= 0 || NULL == szFile)
return false;
FILE* pf = fopen(szFileName, ‘r’);
if (NULL == pf)
return false;
for (int i = 0; i < n; i++)
{
int nWrite = strlen(strs[i]) + 1;
int nWriten = 0;
while (nWriten < nWrite)
nWriten += fwrite(strs[i], nWrite, sizeof(char), pf);
}
fclose(pf);
return true;
}
fwrite()
Given a word, print out all the combinations of words from the letters that
make it. For example:
bad: abd adb bda dab dba
void _inner_print(char str[], int len, int pos)
{
if (pos == len)
{
cout<
}
for (int i = pos; i < len; i++)
{
swap(str[pos], str[i]);
_inner_print(str, len, pos+1);
swap(str[pos], str[i]);
}
}
Input: bad
step 1: 3, i = 0 - bad
step 2.: 3, i = 1 - abd
step 2.: 3, i = 2 - dabchar
void printAllPermutation(const char* str)
{
if (NULL == str || 0 == *str)
return;
int nLen = strlen(str);
char* strTmp = new char[nLen+1];
strcpy(strTmp, str);
_inner_print(strTmp, nLen, 0);
delete [] strTMp;
}
Serialize a list of strings to a file
Input is a file, an array of string pointers and number of elements in the
array. Serialize all the strings in the given file.
bool serializeStrList(const char* strs[], int n, const char* szFileName)
{
if (NULL == strs || n <= 0 || NULL == szFile)
return false;
FILE* pf = fopen(szFileName, ‘r’);
if (NULL == pf)
return false;
for (int i = 0; i < n; i++)
{
int nWrite = strlen(strs[i]) + 1;
int nWriten = 0;
while (nWriten < nWrite)
nWriten += fwrite(strs[i], nWrite, sizeof(char), pf);
}
fclose(pf);
return true;
}
fwrite()