文档内容
更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
1.输入整型数组求数组的最小数和最大数之和,例如输入1,2,3,4则输出为
5,当输入只有一个数的时候,则最小数和最大数都是该数,例如只输入1,则
输出为2;另外数组的长度不超过50
参考代码:
#include
main()
{
int num[50]={0};
int i,n;
printf(“请输入整型数组的长度(1~50):”);
scanf(“%d”,&n);
printf(“请输入整型数组的元素:”);
for (i=0;inum[j])
min_num=num[j];
}
int sum=min_num+max_num;
printf(“数组中最大与最小值之和:%d\n”,sum);
return 0;
}
2.求两个长长整型的数据的和并输出,例如输入1233333333333333 。。。
3111111111111111111111111.。。。,则输出。。。。
#include
#include
#include
main()
{
char *num1,*num2; //两个长长整型数据更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
char *sum;
// int temp;
int len_num1,len_num2; // 两个长长整型数据的长度
int len_max,len_min;
num1=(char*)malloc(sizeof(char));
num2=(char*)malloc(sizeof(char));
printf(“输入两个长长整型数据:”);
scanf(“%s”,num1);
printf(“输入两个长长整型数据:”);
scanf(“%s”,num2);
len_num1=strlen(num1);
len_num2=strlen(num2);
len_max=(len_num1>=len_num2)? len_num1:len_num2;
len_min=(len_num1<=len_num2)? len_num1:len_num2;
int len_max1=len_max;
sum=(char*)malloc(sizeof(char)*len_max);
memset(sum,0×00,len_max+1);//切忌初始化
for(;len_num1>0&&len_num2>0;len_num1–,len_num2–)
{
sum[len_max--]=((num1[len_num1-1]-’0′)+(num2[len_num2-
1]-’0′));
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
if(len_num1>0)
{
sum[len_max--]=num1[len_num1 - 1 ]-’0′;
len_num1–;
}
if(len_num2>0)
{
sum[len_max--]=num1[len_num2 - 1]-’0′;
len_num2–;
}
for(int j=len_max1;j>=0;j–) //实现进位操作
{
// temp=sum[j]-’0′;
if(sum[j]>=10)
{
sum[j-1]+=sum[j]/10;
sum[j]%=10;
}
}
char *outsum=(char*)malloc(sizeof(char)*len_max1);
j=0;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
while(sum[j]==0) //跳出头部0元素
j++;
for(int m=0;m
#include
#include更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
void stringFilter(const char *p_str, long len, char *p_outstr)
{
int array[256]={0};
const char *tmp = p_str;
for(int j=0;j
#include
#include
void arithmetic(const char *input, long len, char *output)更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
char s1[10];
char s2[10];
char s3[10];
int cnt = 0;
int len_input=strlen(input);
for(int i=0;i’9′)
{
*output++ = ’0′;
*output = ‘\0′;
return;
}
}
int len_s3=strlen(s3);
for(i=0;i’9′)
{
*output++ = ’0′;
*output = ‘\0′;
return;
}
}
int x = atoi(s1);
int y = atoi(s3);
if(s2[0]==’+')
{
int result = x+y;
itoa(result,output,10);
}
else if(s2[0]==’-')
{
int result = x-y;
itoa(result,output,10);
}
else更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
*output++ = ’0′;
*output = ‘\0′;
return;
}
}
void main()
{
char str[] = {“10 – 23″};
char outstr[10];
int len = strlen(str);
arithmetic(str,len,outstr);
printf(“%s\n”,str);
printf(“%s\n”,outstr);
}
6.一组人(n个),围成一圈,从某人开始数到第三个的人出列,再接着从下
一个人开始数,最终输出最终出列的人
(约瑟夫环是一个数学的应用问题:已知n个人(以编号1,2,3…n分别表
示)围坐在一张圆桌周围。从编号为k的人开始报数,数到m的那个人出列;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
他的下一个人又从1开始报数,数到m的那个人又出列;依此规律重复下去,
直到圆桌周围的人全部出列。)
#include
#include
#include
#include
typedef struct Node
{
int data;
struct Node *next;
}LinkList;
LinkList *create(int n)
{
LinkList *p,*q,*head;
int i=1;
p=(LinkList*)malloc(sizeof(LinkList));
p->data=i;
head=p;
for(i=1;i<=n;i++)更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
q=(LinkList*)malloc(sizeof(LinkList));
q->data=i+1;
p->next=q;
p=q;
}
p->next=head; //使链表尾连接链表头,形成循环链表
return head;
free(p);
p=NULL;
free(q);
q=NULL;
}
void deletefun(LinkList *L,int m)
{
LinkList *p,*q,*temp;
int i;
p=L;
while(p->next!=p)更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
for(i=1;inext;
}
printf(“%5d”,p->data);
temp=p;
q->next=p->next;
p=p->next;
free(temp);
}
printf(“%5d\n”,p->data);
}
int main()
{
int n=7,m=3;
LinkList *head1;
head1=create(n);
deletefun(head1,m);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
return 0;
}
7..输入一串字符,只包含”0-10″和”,”找出其中最小的数字和最大的数字
(可能不止一个),输出最后剩余数字个数。如输入 “3,3,4,5,6,7,7″
#include
#include
#include
void main()
{
char str[100];
printf(“输入一组字符串:\n”);
scanf(“%s”,&str);
int len=strlen(str);
int array[100];
int count=0;
for(int i=0;i=’0′&&str[i]<=’9′)
array[count++]=str[i]-’0′;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
}
array[count]=’\0′;
int result=count;
int min=array[0];
int max=array[0];
for(int j=0;jarray[j])
min=array[j];
}
for(int k=0;k
#include
#define N 5
int main()
{
int Height[N];
int dmin;
int H1,H2;
int i,j,temp;
printf(“请输入一组身高在170到190之间的数据(共5个):
\n”);
for(int k=0;kHeight[j];j++)
{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
temp=Height[j-1];
Height[j-1]=Height[j];
Height[j]=temp;
}
H1=Height[0];
H2=Height[1];
dmin=H2-H1;
for(int m=2;m
#include
#include
#include
int delete_sub_str(const char *str,const char *sub_str,char *result)
{
assert(str != NULL && sub_str != NULL);
const char *p,*q;
char *t,*temp;
p = str;
q = sub_str;
t = result;
int n,count = 0;
n = strlen(q);
temp = (char *)malloc(n+1);
memset(temp,0×00,n+1);
while(*p)
{
memcpy(temp,p,n);
if(strcmp(temp,q) == 0 )更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
count++;
memset(temp,0×00,n+1);
p = p + n;
}
else
{
*t = *p;
p++;
t++;
memset(temp,0×00,n+1);
}
}
free(temp);
return count;
}
void main()
{
char s[100] = {‘\0′};
int num =
delete_sub_str(“123abc12de234fg1hi34j123k”,”123″,s);
printf(“The number of sub_str is %d\r\n”,num);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
printf(“The result string is %s\r\n”,s);
}
10. 要求编程实现上述高精度的十进制加法。要求实现函数:
void add (const char *num1, const char *num2, char *result)
【输入】num1:字符串形式操作数1,如果操作数为负,则num1[0]为符号
位’-’
num2:字符串形式操作数2,如果操作数为负,则num2[0]为符号位’-’
【输出】result:保存加法计算结果字符串,如果结果为负,则result[0]为
符号位。
#include
#include
#include
void move(char *str, int length) //移除字母前的”-”符号
{
if(str[0] != ‘-’)
return;
int i;
for(i = 0; i < length-1; i++)
str[i] = str[i+1];
str[i] = ‘\0′;
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int remove_zero(char *result, int length)
{
int count = 0;
for(int i = length-1; i > 0; i–) //从最后开始移除0,直到遇到非0数字,
只对最初位置上的0不予判断
{
if(result[i] == ’0′)
{
result[i] = ‘\0′;
count++;
}else
return length-count;
}
return length – count;
}
void reverse(char *result, int length) //将字符串倒转
{
char temp;
for(int i = 0; i <= (length-1)/2; i++)
{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
temp = result[i];
result[i] = result[length-1-i];
result[length-1-i] = temp;
}
}
int real_add(char *str1, char *str2, char *result, const bool flag)
{
int len1 = strlen(str1);
int len2 = strlen(str2);
int n1, n2, another = 0; //another表示进位
int cur_rs = 0; //表示result的当前位数
int i, j;
int curSum;
for(i = len1-1, j = len2-1; i >= 0 && j >= 0; i–, j–)
{
n1 = str1[i] – ’0′;
n2 = str2[j] – ’0′;
curSum = n1 + n2 + another;
result[cur_rs++] = curSum % 10 + ’0′;
another = curSum / 10;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
}
if(j < 0)
{
while(i >= 0) //遍历str1剩余各位
{
n1 = str1[i--] – ’0′;
curSum = n1 + another;
result[cur_rs++] = curSum % 10 + ’0′;
another = curSum / 10;
}
if(another != 0) //如果还有进位未加上
result[cur_rs++] = another + ’0′;
}
else
{
while(j >= 0)
{
n2 = str2[j--] – ’0′;
curSum = n2 + another;
result[cur_rs++] = curSum % 10 + ’0′;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
another = curSum / 10;
}
if(another != 0)
result[cur_rs++] = another + ’0′;
}
result[cur_rs] = ‘\0′;
cur_rs = remove_zero(result, cur_rs);
if(!flag)
{
result[cur_rs++] = ‘-’;
result[cur_rs] = ‘\0′;
}
reverse(result, strlen(result));
return cur_rs;
}
int real_minus(char *str1, char *str2, char *result) //使用str1减去
str2
{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
char big[100], small[100];
int big_len, sml_len;
int len1 = strlen(str1);
int len2 = strlen(str2);
bool flag = false; //用于标记str2是否比str1大
if(len1 < len2)
flag = true;
else if(len1 == len2)
{
if(strcmp(str1, str2) == 0)
{
result[0] = ’0′;
result[1] = ‘\0′;
return 1;
}else if(strcmp(str1,str2) < 0)
flag = true;
}
if(flag) //将str1和str2交换,确保str1指向的值是其中较大者,最后通
过flag确定要不要给前面加-号更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
char *temp = str1;
str1 = str2;
str2 = temp;
len1 = strlen(str1);
len2 = strlen(str2);
}
int n1, n2, another = 0; //another表示是否有借位
int i, j;
int cur_rs = 0;
int curMinus;
for(i = len1-1, j = len2-1; i>=0 && j>=0; i–,j–)
{
n1 = str1[i] – ’0′;
n2 = str2[j] – ’0′;
if(n1 >= n2+another)
{
result[cur_rs++] = (n1-n2-another) +’0′;
another = 0;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
}
else
{
result[cur_rs++] = (n1+10-n2-another) + ’0′;
another = 1;
}
}
while(i >= 0)
{
n1 = str1[i--] – ’0′;
if(another != 0)
{
n1 -= another;
another = 0;
}
result[cur_rs++] = n1 + ’0′;
}
result[cur_rs] = ‘\0′;
cur_rs = remove_zero(result, cur_rs);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
if(flag)
{
result[cur_rs++] = ‘-’;
result[cur_rs] = ‘\0′;
}
reverse(result, cur_rs);
return cur_rs;
}
void addi(const char *num1, const char *num2, char *result)
{
int len1 = strlen(num1);
int len2 = strlen(num2);
int rs_len;
if(!len1 || !len2)
return;
char str1[100], str2[100];
strncpy(str1, num1, len1);
str1[len1] = ‘\0′;
strncpy(str2, num2, len2);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
str2[len2] = ‘\0′;
if(str1[0] == ‘-’ && str2[0] == ‘-’)
{
move(str1, len1);
move(str2, len2);
rs_len = real_add(str1, str2, result, false);
}else if(str1[0] == ‘-’)
{
move(str1, len1);
rs_len = real_minus(str2, str1, result);
}
else if(str2[0] == ‘-’)
{
move(str2, len2);
rs_len = real_minus(str1, str2, result);
}else
rs_len = real_add(str1, str2, result, true);
}
//int main(int argc, char *argv[])更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int main()
{
char num1[100],num2[100];
printf(“请输入两个整型数据:\n”);
scanf(“%s%s”,num1,num2);
char result[100];
memset(result, 0, 100);
addi(num1,num2, result);
printf(“%s\n”, result);
return 0;
}
11.描述:10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如
下:
(1) 及格线是10的倍数;
(2) 保证至少有60%的学生及格;
(3) 如果所有的学生都高于60分,则及格线为60分
输入:输入10个整数,取值0~100
输出:输出及格线,10的倍数
#include
void bubblesort(int arr[])更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
int i,j,temp;
for(i=0;i<10;i++)
for(j=0;j<9-i&&arr[j]>arr[j+1];j++)
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
int GetPassLine(int a[])
{
bubblesort(a);
if(a[0]>=60)
return 60;
else
return (((int)a[4]/10)*10);
}
main()更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
int a[10]={0};
int result;
printf(“请随机输入10个成绩(0-100):\n”);
scanf(“%d%d%d%d%d%d%d%d%d%d”,&a[0],&a[1],&a[2],&a[3],&a[4],
&a[5],&a[6],&a[7],&a[8],&a[9]);
printf(“\n”);
result=GetPassLine(a);
printf(“及格线为:%d\n”,result);
return 1;
}
12.描述:一条长廊里依次装有n(1 ≤ n ≤ 65535)盏电灯,从头到尾编号1、
2、3、…n-1、n。每盏电灯由一个拉线开关控制。开始,电灯全部关着。
有n个学生从长廊穿过。第一个学生把号码凡是1的倍数的电灯的开关拉一下;
接着第二个学生把号码凡是2的倍数的电灯的开关拉一下;接着第三个学生把
号码凡是3的倍数的电灯的开关拉一下;如此继续下去,最后第n个学生把号
码凡是n的倍数的电灯的开关拉一下。n个学生按此规定走完后,长廊里电灯有
几盏亮着。注:电灯数和学生数一致。
输入:电灯的数量
输出:亮着的电灯数量
样例输入:3
样例输出:1更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
#include
#define Max_Bubl_Num 65535
int GetLightLampNum(int n)
{
int BublNum[Max_Bubl_Num]={0}; //0表示灯灭,1表示灯亮
unsigned int i,j;
unsigned int count=0;
for(i=1;i<=n;i++)
for(j=i;j<=n&&j%i==0;j++)
{
BublNum[j-1]+=1;
BublNum[j-1]=BublNum[j-1]%2;
}
for(int k=0;k
#include更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
#include
#include
using namespace std;
#define MAX 35
#define SUBWAY_A 20
#define SUBWAY_B 15
typedef struct node{
int adjvex;
struct node *next;
}edgenode;
typedef struct{
char name[10];
bool flag;
edgenode *link;
}vexnode;
const char subway_name1[SUBWAY_A]
[10]={“A1″,”A2″,”A3″,”A4″,”A5″,”A6″,”A7″,”A8″,”A9″,
”T1″,”A10″,”A11″,”A12″,”A13″,”T2″,”A14″,”A15″,”A16″
,”A17″,”A18″};更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
const char subway_name2[SUBWAY_B]
[10]={“B1″,”B2″,”B3″,”B4″,”B5″,”B6″,”B7″,”B8″,”B9″,
”B10″,”B11″,”B12″,”B13″,”B14″,”B15″};
void creat(vexnode ga[]){
int i;
edgenode *p;
for(i=0;iadjvex=i-1;
p->next=NULL;
ga[i].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=i+1;
p->next=NULL;
ga[i].link->next=p;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
if(i==9){
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+4;
p->next=NULL;
ga[i].link->next->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+5;
p->next=NULL;
ga[i].link->next->next->next=p;
}
else if(i==14){
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+9;
p->next=NULL;
ga[i].link->next->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+10;
p->next=NULL;
ga[i].link->next->next->next=p;
}
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A-1;
p->next=NULL;
ga[0].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=1;
p->next=NULL;
ga[0].link->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A-2;
p->next=NULL;
ga[SUBWAY_A-1].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=0;
p->next=NULL;
ga[SUBWAY_A-1].link->next=p;
//B地铁建邻接表
for(i=1;iadjvex=SUBWAY_A+i-1;
p->next=NULL;
ga[i+SUBWAY_A].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+i+1;
p->next=NULL;
ga[i+SUBWAY_A].link->next=p;
}
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+3;
p->next=NULL;
ga[SUBWAY_A+4].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=9;
p->next=NULL;
ga[SUBWAY_A+4].link->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=9;
p->next=NULL;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
ga[SUBWAY_A+5].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+6;
p->next=NULL;
ga[SUBWAY_A+5].link->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+8;
p->next=NULL;
ga[SUBWAY_A+9].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=14;
p->next=NULL;
ga[SUBWAY_A+9].link->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=14;
p->next=NULL;
ga[SUBWAY_A+10].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+11;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
p->next=NULL;
ga[SUBWAY_A+10].link->next=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+1;
p->next=NULL;
ga[SUBWAY_A].link=p;
p=(edgenode*)malloc(sizeof(edgenode));
p->adjvex=SUBWAY_A+SUBWAY_B-2;
p->next=NULL;
ga[SUBWAY_A+SUBWAY_B-1].link=p;
// 打印各邻接节点
for(i=0;i%s”,ga[s->adjvex].name);
s=s->next;
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
printf(“\n”);
}
}
int main(){
vexnode ga[MAX];
creat(ga);
int i;
char str[2][10];
while(scanf(“%s%s”,str[0],str[1])!=EOF){
int temp=0;
for(i=0;iq;
q.push(ga[temp]);
ga[temp].flag=false;
int count=0;
int start=0;
int end=1;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
bool find_flag=false;
while(!q.empty()){
if(find_flag) break;
count++;
printf(“************************\n”);
printf(“第%d层搜索:”,count);
int temp_end=end;
while(startadjvex].flag){
q.push(ga[s->adjvex]);
ga[s->adjvex].flag=false;
end++;
//printf(“%s “,ga[s->adjvex].name);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
}
s=s->next;
}
q.pop();
start++;
}
printf(“\n”);
}
printf(“%d\n”,count);
}
return 0;
}
14.字串转换
问题描述:
将输入的字符串(字符串仅包含小写字母’a'到’z'),按照如下规则,循环
转换后输出:a->b,b->c,…,y->z,z->a;若输入的字符串连续出现两个字母相
同时,后一个字母需要连续转换2次。例如:aa 转换为 bc,zz 转换为 ab;
当连续相同字母超过两个时,第三个出现的字母按第一次出现算。
要求实现函数:
void convert(char *input,char* output)
【输入】 char *input , 输入的字符串
【输出】 char *output ,输出的字符串
【返回】无
#include
#include
#include更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
void convert(char *input,char* output)
{
if(input==NULL)
return;
char temp=’\0′;
int len_input=strlen(input);
int i;
int flag=0;
for(i=0;i
#include
#include
void my_word(char input[],char output[])
{
char *p;
char *temp;
char *word[10];
int len_input=strlen(input);
int i,j;
char except[] = “,”;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
char *blank = ” “;
i=0;
for (i=0;i’Z'&&input[i]<’a') ||
input[i]>’z')
{
input[i]=’,';
}
}
j=0;
/*保存取出的单词*/
p= strtok(input,except);
while(NULL!=p)
{
word[j++]=p;
p= strtok(NULL,except);
}
for(i=0;i<5;i++)
printf(“%s”,word[i]);
/*对单词按照长度降序排序,冒泡法*/更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
for (i=0;i<5;i++)
{
for (j=1;j<5-i;j++)
{
if(strlen(word[j-1])更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int a[] = {1,1,2,4,3,3,2,5};
int findXorSum(int* a, int len)
{
int i = 0;
int temp = 0;
for(; i < len; i++)
{
temp = temp ^ a[i];
}
return temp;
}
int findFirstBit1(int n)
{
int count = 1;
while(!( n & 1))
{
n = n>>1;
count++;
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
return count;
}
int isBit1(int a, int count)
{
a = a >> count-1;
return (a & 1);
}
void findTwoUnique(int* a, int len)
{
int i = 0;
int m = 0, n = 0;
int temp = findXorSum(a, len);
int count = findFirstBit1(temp);
for(; i < len; i++)
{
if(isBit1(a[i],count))
{
m = m ^ a[i];
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
else
{
n = n ^ a[i];
}
}
printf(“%d, %d”, m, n);
}
int main()
{
findTwoUnique(a,8);
}
18.链表翻转。给出一个链表和一个数k,比如链表1→2→3→4→5→6,k=2,
则翻转后2→1→4→3→6→5,若k=3,翻转后3→2→1→6→5→4,若k=4,翻转
后4→3→2→1→5→6,用程序实现
思想:采用遍历链表,分成length/k组,对每组进行逆转,逆转的同时要将逆
转后的尾和头连接起来
//#include “stdafx.h”
#include “stdio.h”
#include “stdlib.h”
#include
typedef struct Node{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int value;
Node* next;
}LinkList;
void Converse(LinkList* pPre,LinkList* pCur)
{ //链表逆转
LinkList* p = NULL;
LinkList* pNext = NULL;
p = pPre->next;
LinkList* p1 = NULL;
if(pCur!=NULL)
pNext = pCur->next;
while( p!=pNext)
{
p1 = p->next;
p->next = pPre;
pPre = p;
p = p1;
}
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int main()
{
int count = 0, k,i=0,j=0,flag = 1,length=0,groups = 0;
scanf(“%d”,&k);
LinkList* pPre = (LinkList*)malloc(sizeof(LinkList));
LinkList* pCur = (LinkList*)malloc(sizeof(LinkList));
LinkList* pNext = (LinkList*)malloc(sizeof(LinkList));
LinkList* head = NULL;
LinkList* pTempTail = NULL; //指向逆转之后的尾部
LinkList* pTempHead = NULL;
pCur->value = 1;
pPre = pCur; //创建初始链表
for(i=2;i<=6;i++) {
LinkList* node = (LinkList*)malloc(sizeof(LinkList));
node->value = i;
pCur->next = node;
pCur = node;
}
pCur->next = NULL;//最后一定要置NULL,c++中用new则无须置
NULL更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
pCur = pPre;
while(pCur!=NULL)
{
length++;
pCur = pCur->next;
}
i=0;
groups = length/k; //分成K段
pCur = pPre;
while(i<=groups)
{
count = 0;
while(countnext;
count++;
}
if(inext;
pTempHead = pCur; /*没做翻转之前的头部,变成了
翻转之后的尾部*/
if(flag == 0)
{
pTempTail->next = pTempHead;
}
pTempTail = pPre;
Converse(pPre,pCur);
//pTempTail = pPre;
if(flag==1)
{
head = pCur;
flag = 0;
}
pCur = pNext;
}
else
{
pTempTail->next = pNext;
}
pPre = pCur;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
i++;
}
pCur = head;
while(jvalue);
pCur = pCur->next;
}
printf(“\n”);
// system(“pause”);
return 0;
}
19.链表相邻元素翻转,如a->b->c->d->e->f-g,翻转后变为:b->a->d->c-
>f->e->g
#include
#include
#include
typedef struct node{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
char val;
struct node* pNext;
}Node;
Node* CreateList(int n);
void Traverslist(Node* pHead);
Node* TransNeighbor(Node* pHead);
int main(){
Node* pHead = CreateList(7);
printf(“before transform\n”);
Traverslist(pHead);
TransNeighbor(pHead);
printf(“\nafter transform\n”);
Traverslist(pHead);
getchar();
return 1;
}
//创建新链表
Node* CreateList(int n){
Node* pHead = (Node*)malloc(sizeof(Node));更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
Node* pTail = pHead;
pTail->pNext=NULL;
int i;
for(i=0; i < n; i++){
Node* pNew = (Node*)malloc(sizeof(Node));
pNew->val = ‘a’+i;
pTail->pNext = pNew;
pNew->pNext = NULL;
pTail = pNew;
}
return pHead;
}
void Traverslist(Node* pHead){
Node* p = pHead->pNext;
int isFirst = 0;
while(p!= NULL)
{
if(isFirst==0)
{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
printf(“%c”,p->val);
isFirst=1;
}else{
printf(“->%c”,p->val);
}
p = p->pNext;
}
return;
}
Node* TransNeighbor(Node* pHead){
Node* p = pHead->pNext;
while(p->pNext!=NULL && p->pNext->pNext!=NULL)
{
char value = p->val;
p->val=p->pNext->val;
p->pNext->val=value;
p=p->pNext->pNext;
}
return pHead;
}更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
20.输入一串字符串,其中有普通的字符与括号组成(包
括’(’、’)’、’[',']‘),要求验证括号是否匹配,如果匹配则输出
0、否则输出1.
#include
#include
//#define MAX 100
int main()
{
char a[100],c[]=”(((1+2))”;
int i=0,j=0;;
int flag=0;
while(c[i]!=NULL&&flag==0)
{
switch(c[i])
{
case(‘(‘):
case(‘['):
a[j++]=c[i];break;
case(‘)’):
if(a[j-1]==’(‘)
{
a[j-1]=’\0′;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
j–;
}
else
flag=1;
break;
case(‘]’):
if(a[j-1]==’[')
{
a[j-1]=’\0′;
j–;
}
else
flag=1;
break;
}
i++;
}
if(j!=0) flag=1;
printf(“%d\n”,flag);
return 0;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
}
方法2:#include
#include
#include // !!!分配内存头文件
#define m 20
typedef char ElemType;
typedef struct
{
ElemType stack[m];
int top;
}stacknode;
stacknode *sp;
Init(stacknode *st)
{
st->top=0;
return 0;
}
void Push(stacknode *st,ElemType x)
{
if(st->top==m)
printf(“The stack is overflow!\n”);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
else
{
st->top=st->top+1;
st->stack[st->top]=x;
}
}
void Pop(stacknode *st)
{
st->top=st->top-1;
}
main()
{
char s[m]=”(()”;
int i;
printf(“Creat a stack!\n”);
sp = (stacknode *)malloc(sizeof(stacknode)); // !!!添加的语句
Init(sp);
printf(“Input a expression:\n”);
// gets(s);
for(i=0;itop==0)
printf(“左右括号是匹配的!\n”);
else
printf(“左右括号是不匹配的!\n”);
return 0;
}
21.将第一行中含有第二行中”23″的数输出并排序
2.输入一行数字:123 423 5645 875 186523
在输入第二行:23
将第一行中含有第二行中”23″的数输出并排序
结果即:123 423 186523
#include
#define M 20
int main()
{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int a[M];
int i,j,s,temp;
int sort[M],t=0;
char c=’ ‘;
i=0;
while(c!=’\n’)
{
scanf(“%d%c”,&temp,&c);
a[i++]=temp;
}
scanf(“%d”,&s);
for(j=0;jsort[j+1])
{
temp=sort[j+1];
sort[j+1]=sort[j];
sort[j]=temp;
}
}
for(i=0;i
#include
int main()
{
char c[200]={‘\0′};
scanf(“%s”,&c);
int n,i,j;
int len=strlen(c);
scanf(“%d”,&n);
for(i=1;i<=len;i++)
{
j=i%n;
printf(“%c”,c[i-1]);
if(j==0)
printf(“\n”);
}
if(j!=0)
for(i=j+1;i<=n;i++)
printf(“0″);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
return 0;
}
23将 电话号码 one two 。。。nine zero
翻译成1 2 。。9 0
中间会有double
例如输入:OneTwoThree
输出:123
输入:OneTwoDoubleTwo
输出:1222
输入:1Two2 输出:ERROR
输入:DoubleDoubleTwo 输出:ERROR
有空格,非法字符,两个Double相连,Double位于最后一个单词都错误
#include
#include
#include
int main()
{
char a[11]
[11]={“zero”,”one”,”two”,”three”,”four”,”five”,”six”,”
seven”,”eight”,”nine”,”double”};
char temp[11], c=’ ‘;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int i,j,f,d=0;
while(c!=’\n’)
{
scanf(“%s%c”,&temp,&c);
f=0;
for(j=0;j<11;j++)
{
if(!strcmp(temp,a[j])&&j<10)
{
printf(“%d”,j);
f=1;
if(d==1)
{
printf(“%d”,j);
d=0;
}
}
else if(!strcmp(temp,a[j])&&j==10)
{
d=1;
f=1;更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
}
}
if(f==0)
break;
}
if(d==1||f==0)
printf(“error\n”);
printf(“\n”);
return 0;
}
24.将整数倒序输出,剔除重复数据
输入一个整数,如12336544,或1750,然后从最后一位开始倒过来输出,最后
如果是0,则不输出,输出的数字是不带重复数字的,所以上面的输出是
456321和571。如果是负数,比如输入-175,输出-571。
#include
#include
#include
#include
int main()更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
char *input=(char*)malloc(sizeof(char));
scanf(“%s”,input);
int a[10]={0},i,flag=0,flag1=0;
int len=strlen(input);
if(input[0]==’-')
{
flag=1;
for(i=0;i=0;ii–)
{
if(n[ii]!=0||flag1!=0)
{
printf(“%d”,n[ii]);
flag1=1;
}
}
printf(“\n”);
return 0;
}
25.编程的时候,if条件里面的”(“、”)”括号经常出现不匹配的情况导
致编译不过,请编写程序检测输入一行if语句中的圆括号是否匹配正确。同时
输出语句中出现的左括号和右括号数量,如if((a==1)&&(b==1))是正确的,而更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
if((a==1))&&(b==1))是错误的。注意if语句的最外面至少有一对括号。提示:
用堆栈来做。
输入:if((a==1)&&(b==1))
输出:RIGTH 3 3
输入:if((a==1))&&(b==1))
输出:WRONG 3 4
#include
#include
int main()
{
char s[800]={‘\0′};
scanf(“%s”,&s);
// char s[]=”if(())”;
int len=strlen(s);
int i,left=0,right=0;
int a[50],k=0,flag=1;
for(i=0;i0)
{
a[k-1]=0;
k–;
}
else
flag=0;
}
if((i==2&&s[i]!=’(‘)||(i==len-1&&s[i]!=’)'))
flag=0;
}
if(a[0]==0&&flag!=0)
printf(“RIGHT”);
else
printf(“WRONG”);更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
printf(“%d %d\n”,left,right);
return 0;
}
约瑟夫问题
输入一个由随机数组成的数列(数列中每个数均是大于0的整数,长度已知),
和初始计数值m。从数列首位置开始计数,计数到m后,将数列该位置数值替换
计数值m,并将数列该位置数值出列,然后从下一位置从新开始计数,直到数
列所有数值出列为止。如果计数到达数列尾段,则返回数列首位置继续计数。
请编程实现上述计数过程,同时输出数值出列的顺序
比如:输入的随机数列为:3,1,2,4,初始计数值m=7,从数列首位置开始计数
(数值3所在位置)
第一轮计数出列数字为2,计数值更新m=2,出列后数列为3,1,4,从数值4所
在位置从新开始计数
第二轮计数出列数字为3,计数值更新m=3,出列后数列为1,4,从数值1所在
位置开始计数
第三轮计数出列数字为1,计数值更新m=1,出列后数列为4,从数值4所在位
置开始计数
最后一轮计数出列数字为4,计数过程完成。
输出数值出列顺序为:2,3,1,4。
要求实现函数:
void array_iterate(int len, int input_array[], int m, int
output_array[])
【输入】 int len:输入数列的长度;
int intput_array[]:输入的初始数列
int m:初始计数值
【输出】 int output_array[]:输出的数值出列顺序
【返回】无更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
示例:
输入:int input_array[] = {3,1,2,4},int len = 4, m=7
输出:output_array[] = {2,3,1,4}
解题思路:
每次出列一个数值,需要对m、input_array、output_array、输出位置
outPos、起始位置startPos进行更新;
对于输出位置outPos的计算是关键!通过分析可知,
outPos=(startPos+m-1)%num
代码实现:
vie w plai n cop y t o clipboar d prin t ?
#include
void print_array(int len, int array[])
{
for(int i=0; i=0; nIter–)
{
outPos=(m+startPos-1)%num;
m=input_array[outPos];
startPos=outPos;
printf(“outPos is %d, new m is %d\n”, outPos, m);
output_array[len-nIter-1]=input_array[outPos];
for(int i=outPos; i
#include
#include
int main()
{
char *num=”323324423343″;
int a[10]={0};
int len=strlen(num);
int i,j,temp,count=0,maxnum=0;
printf(“%d\n”,len);
for(i=0;ia[j])?temp1:a[j];
printf(“%d %d\n”,a[j],j);
}
}
printf(“数字出现次数为:%d\n”,count);
printf(“最大次数为:%d\n”,temp1);
return 0;
}
28..字符串首字母转换成大写
举例:
输入:this is a book
返回:This Is A Book
#include更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
#include
#include
int main()
{
char input[]=”this is a book”;
char output[256]={‘\0′};
int i,len;
len=strlen(input);
printf(“变换前的字符串为:%s\n”,input);
for(i=0;i
#include
#include
#include
void DivideString(const char *pInputStr, long lInputLen, char
*pOutputStr)
{更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
int cnt;
const char *p=pInputStr;
while(*p!=NULL)
{
if(*p!=’ ‘)
{ cnt = 0;
*pOutputStr++ = *p++;
}
else
{ cnt++;
p++;
if(cnt==1)
*pOutputStr++ = ‘,’;
}
}
*pOutputStr++ = ‘,’;
*pOutputStr = ‘\0′;
}
void main()更多企业校园招聘笔试面试试题合集下载: http://bimian.xuanjianghui.com.cn/
{
char *str = “abc def gh i d”;
long len = strlen(str);
char *outstr = (char*)malloc(sizeof(str));
//char outstr[100];
DivideString(str,len,outstr);
printf(“%s”,outstr);
printf(“\n”);
}