
面试题
weizhongdai
这个作者很懒,什么都没留下…
展开
-
100的阶乘末尾有多少个零?
100! = m * 10n; 其中 m不被10整除,n就是100!末尾零的个数。由于2的个数比5多,所以只要计算5的个数就可以了。 #include #include using namespace std;int main(int argc, char *argv[]){ int count = 0; for (int i=1; i!=101;原创 2009-11-06 12:08:00 · 962 阅读 · 0 评论 -
问Calc(9999)的值是多少。
int Calc(unsigned int x){int count=0;while(x){printf(”x=%i/n”,x);count++;x=x&(x-1);}return count;}问Calc(9999)的值是多少。 x = x&(x-1) 的作用是将x最右边的1变为0;9999 的二进制表示为 10011100001111。原创 2009-11-07 13:03:00 · 588 阅读 · 0 评论 -
有一段文本,统计其中的单词数
#include #include int main(){ int c; int flag = 0; // flag=0 表示当前位于单词间。 int count = 0; while ((c = getchar()) != EOF) { if (isalpha(c)) { if (flag == 0) // 进入单原创 2009-11-07 12:10:00 · 1796 阅读 · 1 评论 -
实现对数组的降序排序
#include #define N 9int array[N] = {45, 56, 76, 234, 1, 34, 23, 2, 3}; //数字任意给出void sort();int main(){ int m; sort(); for (m=0; m<N; m++) printf("%d ", array[m]); system("P原创 2009-11-07 09:18:00 · 1477 阅读 · 0 评论 -
设计函数 int atoi(char *s)。
/*设计函数 int atoi(char *s)函数说明atoi() 会扫描参数s字符串,跳过前面的空格字符,直到遇上数字或正负符号才开始转换,而再遇到非数字或字符串结束时(/0)才结束转换,并将结果返回。返回值:返回转换后的整型数相关函数 isspace,isdigit 表头文件 #include */int atoi(char *s){ int原创 2009-11-07 08:22:00 · 1171 阅读 · 0 评论 -
写一个函数,将其中的/t都转换成4个空格。
string replaceTab(const string& strSrc){//strSrc 源字符串, 将源字符串中的/t转换为4个空格 string strDes; for (int i=0; i!=strSrc.size(); i++) { if (strSrc[i] == /t) //转换成4个空格 { strDes原创 2009-11-06 21:57:00 · 2440 阅读 · 1 评论 -
输入一个整数, 用a-z表示, 相当于从10进制转换到26进制 比如27->aa, 28->ab.
#include #include #include using namespace std;int main(int argc, char *argv[]){ string az("zabcdefghijklmnopqrstuvwxy"); string dest; int i; cin >> i; do {原创 2009-11-06 20:01:00 · 1670 阅读 · 0 评论 -
输出1到100中的偶数,一行5个
#include using namespace std;int main(){ for (int i=1; i != 101; i++) { if (!(i%2)) cout << i << " "; if (!(i%10)) cout << endl; } system("PAUSE"); return原创 2009-11-06 19:55:00 · 3215 阅读 · 0 评论 -
字符串数组按照字母排序
int strcmp(const char* dest, const char* src){ assert((NULL != dest) && (NULL != src)); while (*dest && *src && (*dest == *src)) { dest++; src++; } return *dest - *src;}转载 2009-11-06 18:59:00 · 967 阅读 · 0 评论 -
为一个整型数组添加一组随机数
#include using namespace std;const int SIZE = 100;int main(){ int a[SIZE]; srand(time(NULL)); for(int i=0; i!= SIZE; i++) { a[i] = rand()%SIZE + 1; } for (int i=0; i!=原创 2009-11-07 21:41:00 · 561 阅读 · 0 评论 -
请编写一个类, 使其具有整形变量i的i++以及++i的功能
#include using namespace std;class Int{public: Int(int i): i_data(i) {} int operator++(); int operator++(int); friend ostream& operator<<(ostream& os, Int vi);private: int i_原创 2009-11-07 20:50:00 · 741 阅读 · 0 评论 -
编一个程序求质数的和
int F(int n){ // 先考虑2种特殊情形 if (n == 1) return 1; if (n == 2) return 3; vector ivec; ivec.push_back(1); ivec.push_back(2); int i = 3; vector::iterator iter; whil原创 2009-11-07 19:23:00 · 775 阅读 · 0 评论 -
Delete a node WITHOUT using the HEAD pointer.
/*Delete a node WITHOUT using the HEAD pointerPARAM p: A pointer pointed to a node in the middle of the linked list.RETURN: void */void Delete(Node* p){ Node* q = p->next; while (q->n原创 2009-11-07 12:12:00 · 447 阅读 · 0 评论 -
完成下列程序
完成下列程序**.*.*..*..*..*…*…*…*…*….*….*….*….*….*…..*…..*…..*…..*…..*…..*……*……*……*……*……*……*……*…….*…….*…….*…….*…….*…….*…….*……. #include using namespace std;const int原创 2009-11-07 08:24:00 · 458 阅读 · 0 评论 -
一个字符串插入到另一个字符串
#include #include using namespace std;/* * 将src插入到des的第pos个字符位置后面 */void insert(string &des, const string &src, int pos){ // 构造临时对象str,放置插入结果。 string str(des, 0, pos); str +=原创 2009-11-07 15:35:00 · 1048 阅读 · 0 评论