面试题目练习
文章平均质量分 62
u010525281
这个作者很懒,什么都没留下…
展开
-
不要多余的空格
输入一个字符串并将它输出,以Ctrl+Z组合键表示输入完毕,要求将输入的字符串中多余1个的连续空格符合并为1个。#includevoid inputString(){ char c, lastc = 'a'; c = getchar(); while (c!=EOF) { if (c != ' ')原创 2016-04-14 16:57:30 · 244 阅读 · 0 评论 -
删除字符串中指定的字符
#include#includeusing namespace std;void decChar(char*str, char c){ char*q, *p = str; while (*p!='\0') { if (*p == c) { q = p; do原创 2016-04-15 21:04:07 · 386 阅读 · 0 评论 -
求两个数组中都出现的元素
#include#includeusing namespace std;void func(int array1[],int n1, int array2[],int n2){ int i, j; //int n1, n2;// n1 = strlen(array1); strlen 求字符串长度。// n2 = strlen(array原创 2016-04-15 18:35:44 · 2261 阅读 · 0 评论 -
计算一个字节中有多少位被置为1
#include#includeusing namespace std;int bitNumber(unsigned char c) //因为字节位数的原因,只能用unsigned char{ int count = 0; int i; unsigned char cmp = (0x1 for (i =原创 2016-04-16 08:57:31 · 3349 阅读 · 0 评论 -
在字符串中有序插入一个新字符
#include#includeusing namespace std;int main(){ char str[11] = "abdfhilpt"; int i, j; cout char c; cout cin >> c; for (i = 0; i if (str[i] >= c)b原创 2016-04-16 09:16:51 · 3522 阅读 · 0 评论 -
按字母顺序排序输出
#include#includeusing namespace std;void strcpy1(char*p1, char*p2){ char temp; temp =* p1; *p1 = *p2; *p2 = temp;}int main(){ char st[20], cs[5][20]; in原创 2016-04-16 10:54:32 · 4005 阅读 · 0 评论 -
求链表的长度
#include#includeusing namespace std;typedef int Elemtype;typedef struct node { Elemtype data; struct node* next;};node* Greatlist(int n){ node*p, *r, *list = NULL; r原创 2016-04-16 13:02:15 · 969 阅读 · 0 评论 -
删除链表中指定位置的元素
#include#includeusing namespace std;typedef int Elemtype;typedef struct node { Elemtype data; struct node* next;};node* Greatlist(int n) //创建链表{ node原创 2016-04-16 15:30:03 · 1387 阅读 · 0 评论 -
测试队列的长度
#include#includeusing namespace std;typedef char elemtype;typedef struct node { elemtype data; struct node*next;};typedef struct LinkQueue { node* front; node* reat;}原创 2016-04-16 16:14:17 · 393 阅读 · 0 评论 -
求二叉树的叶节点
#include#include#includeusing namespace std;typedef struct BiTNode { char data; struct BiTNode *lchild, *rchild;}; void CreatBiTree(BiTNode* *T) //创建二叉树必须得是二级指针{ ch原创 2016-04-16 17:07:45 · 354 阅读 · 0 评论 -
计算字符串中包含的单词数
#include#includeusing namespace std;int latternumber(char*str){ int i, count = 0; int flag ; char* p = str; while (*p!='\0') { if ((*p >= 'A'&&*p = 'a'&&*原创 2016-04-15 20:34:39 · 841 阅读 · 0 评论 -
求两个有序数组的共有元素
#include#includeusing namespace std;void overlap(int array1[], int n1, int array2[], int n2){ int i=0, j=0; while (i { if (array1[i] > array2[j]) j++; else i原创 2016-04-15 20:13:14 · 2256 阅读 · 0 评论 -
统计字符串中连续1和连续0的个数
/*#include#include //自己写的using namespace std;void getmax(char*str){ int len = strlen(str); int max0 = 0, max1 = 0; int temp0 = 0, temp1 = 0; int i; for (i原创 2016-04-15 17:24:55 · 1377 阅读 · 0 评论 -
输出最大和第二大的数
从终端输入10个整数,输出其中最大的数和次打的数。要求输入的10个整数互不相等。#include#includeusing namespace std;int main(){ int a, maxval = -1000, secondval = -1000, i; for (i = 1; i { cin >>原创 2016-04-14 17:07:04 · 698 阅读 · 0 评论 -
求n项之和
编写程序,求分数序列2,3/2,5/3,8/5,13/8.......的前50项之和#include#include#includeusing namespace std;float sum(int n){ float a = 2, b = 1; float sum=0, temp; int i; for (i = 1原创 2016-04-14 17:37:25 · 439 阅读 · 0 评论 -
交换前后字符串
#include#include#include#include#include//#includeusing namespace std;void reverse(char *s){ int len = strlen(s) - 1, i = 0; char tmp; while (i!=len && i {原创 2016-04-14 20:20:24 · 1438 阅读 · 0 评论 -
合并两个字符串
将两个字符串连接,不破坏原有字符串#include#includeusing namespace std;char* consent(char*s1, char*s2){ int len1, len2, len; char *s; len1 = strlen(s1); len2 = strlen(s2); len原创 2016-04-15 09:27:17 · 2106 阅读 · 0 评论 -
递归法累计求和
递归法累计求和#include#includeusing namespace std;int sum(int n){ if (n == 1)return 1; else return sum(n - 1)+n;}int main(){ int n; cout cin >> n;原创 2016-04-15 09:36:07 · 1228 阅读 · 0 评论 -
递归方法求整型数组中最大值
用递归方法找出整型数组中最大值#include#includeusing namespace std;int arrayMax(int array[], int n){ if (n == 1) return array[0]; else { if (array[0] > arrayMax(array + 1,原创 2016-04-15 09:44:45 · 1743 阅读 · 0 评论 -
用递归法改变字符串大小写
大小写字母随意改变,用递归法#include#includeusing namespace std;char upper(char c){ return(c - 'a' + 'A');}void func(char str[], int n, int i){ if (i {原创 2016-04-15 09:59:29 · 462 阅读 · 0 评论 -
用递归法交换字符串前后顺序
用递归法交换字符串前后顺序#include#includeusing namespace std;void reverse(char*s, int len, int i){ char temp; if (i { temp = s[i]; s[i] = s[len-1]; s[len原创 2016-04-15 10:09:59 · 1145 阅读 · 0 评论 -
字符串循环右移
#include#include//#includeusing namespace std;void loopMove(char*str, int n){ int i, j; char temp; int len = strlen(str); //cout for (i = 0; i { te原创 2016-04-15 14:27:33 · 236 阅读 · 0 评论 -
求二叉树中某个字符所在的层数
#include#include#includeusing namespace std;typedef struct BiTNode { char data; struct BiTNode *lchild, *rchild;};void CreatBiTree(BiTNode* *T) //创建二叉树必须得是二级指针{ cha原创 2016-04-16 17:55:24 · 2316 阅读 · 0 评论