怎么用自己的电脑建设网站,做网站常用的小语种有哪些,微信到wordpress,网页制作工具哪个好用第一题、输入一个正整数#xff0c;并编码为字符串进行输出
描述: 1、输入一个正整数#xff0c;并编码为字符串进行输出。 编码规则为#xff1a;数字0-9分别编码为字符a-j 2、输入肯定是正整数#xff0c;不用做错误较验
运行时间限制: 无限制 内存限制: 无限制 输…第一题、输入一个正整数并编码为字符串进行输出
描述: 1、输入一个正整数并编码为字符串进行输出。 编码规则为数字0-9分别编码为字符a-j 2、输入肯定是正整数不用做错误较验
运行时间限制: 无限制 内存限制: 无限制 输入: 正整数
输出: 字符串
样例输入: 123 样例输出: bcd
#include iostream
using namespace std;
void int2str(int n,char* str)
{if (strNULL){return ;}int i0;char temp[20];while (n){temp[i]an%10;n/10;}temp[i]\0;i--;int j0;while (i0){str[j]temp[i--];}str[j]\0;
}
void main()
{int n;cinn;char a[20];int2str(n,a);coutaendl;
}
第二题、 通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序若字符串中出现多个相同的字符将非首次出现的字符过滤掉。 比如字符串“abacacde”过滤结果为“abcde”。 要求实现函数void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr); 【输入】 pInputStr 输入字符串 lInputLen 输入字符串长度 【输出】 pOutputStr 输出字符串空间已经开辟好与输入字符串等长 【注意】只需要完成该函数功能算法中间不需要有任何IO的输入输出 示例 输入“deefd” 输出“def” 输入“afafafaf” 输出“af” 输入“pppppppp” 输出“p” main函数已经隐藏这里保留给用户的测试入口在这里测试你的实现函数可以调用printf打印输出 当前你可以使用其他方法测试只要保证最终程序能正确执行即可该函数实现可以任意修改但是不要改变函数原型。一定要保证编译运行不受影响。
/***************************************************************
通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序若字符串中出现多个相同的字符将非首次出现的字符过滤掉。
比如字符串“abacacde”过滤结果为“abcde”。
要求实现函数void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);
【输入】 pInputStr 输入字符串
lInputLen 输入字符串长度
【输出】 pOutputStr 输出字符串空间已经开辟好与输入字符串等长
【注意】只需要完成该函数功能算法中间不需要有任何IO的输入输出
示例
输入“deefd” 输出“def”
输入“afafafaf” 输出“af”
输入“pppppppp” 输出“p”
main函数已经隐藏这里保留给用户的测试入口在这里测试你的实现函数可以调用printf打印输出
当前你可以使用其他方法测试只要保证最终程序能正确执行即可该函数实现可以任意修改但是不要改变函数原型。一定要保证编译运行不受影响。*************************************************************/#include iostream
#include cstring
#include algorithm
#include string
#include iterator
using namespace std;void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr)
{if (pInputStrNULL||lInputLen1){return;}int n0;//用来存储当前pOutputStr一共从pInputStr获得多少元素for (int i0;ilInputLen;i){if (i0){pOutputStr[n]pInputStr[i];}else{int flag0;for (int j0;jn;j){if (pInputStr[i]pOutputStr[j]){flag-1;break;}}if (flag0){pOutputStr[n]pInputStr[i];}}}
pOutputStr[n]\0;
}
void stringFilter2(const char *pInputStr, long lInputLen, char *pOutputStr)//lInputLen指不包含\0的个数
//第二种写法来自http://blog.csdn.net/net_assassin/article/details/11660869
{bool g_flag[26]{0};if (pInputStrNULL||lInputLen1){return;}int i0;while (*pInputStr!\0){if (g_flag[*pInputStr-a]){pInputStr;}else{pOutputStr[i]*pInputStr;g_flag[*pInputStr-a]1;pInputStr;}}pOutputStr[i]\0;}
//第三种写法
void stringFilter3(const char *pInputStr, long lInputLen, char *pOutputStr)
{// 去除重复字符并排序的字符串,这个程序最终对所有的元素重新做了排序如果没有要求排序则使用前两种方法。if (pInputStrNULL||lInputLen1){return;}string str;copy(pInputStr,pInputStrlInputLen,back_inserter(str));sort(str.begin(),str.end());str.erase(unique(str.begin(),str.end()),str.end());strcpy(pOutputStr,str.c_str());}
//
//void main()
//{
// char *pInputStrdeefd;
// long lInputLenstrlen(pInputStr);
// char *pOutputStrnew char[lInputLen1];
// stringFilter(pInputStr,lInputLen,pOutputStr);
// coutresult isendl;
// coutpOutputStrendl;
// delete[] pOutputStr;
//}void main()
{char *pInputStrabacacde;long lInputLenstrlen(pInputStr);char *pOutputStrnew char[lInputLen1];stringFilter3(pInputStr,lInputLen,pOutputStr);coutresult isendl;coutpOutputStrendl;delete[] pOutputStr;
}