其实很简单,但就是不知道怎么当时在面试现场没想出来。武汉航天软景公司的面试题:
要求:输入整数1234,输出1_2_3_4
代码:
#include <iostream.h>
int main(int n)
{
cout << "please input your number:" << endl;
cin >> n;
int iVal[256];
iVal[0] = n%10;
int iCnt = 0;
char ch = '_';
while((n-iVal[iCnt])>=10)
{
++iCnt;
iVal[iCnt] = ((n - iVal[iCnt - 1])/10)%10;
n = (n - iVal[iCnt - 1])/10;
}
for(int iIndex = iCnt;iIndex >= 1;iIndex--)
cout<<iVal[iIndex]<<ch;
cout<<iVal[0]<<endl;
return 0;
}
本文介绍了一道武汉航天软景公司的面试题解决方案:如何将整数1234转换为带有下划线分隔的字符串形式1_2_3_4。通过一个简单的C++程序实现该功能,展示了取模、除法等基本运算的应用。

1298

被折叠的 条评论
为什么被折叠?



