219华为校园招聘面试
1.输入整型数组求数组的最小数和最大数之和,例如输入1,2,3,4 则输出为 5, 当输入只有一个数的时候,则最小数和最大数都是该数,例如只输入1,则输出 为 2;另外数组的长度不超过 50 参考代码: #include main() { int num[50]={0}; int i,n; printf(“请输入整型数组的长度(1~50):”); scanf(“%d”, printf(“请输入整型数组的元素:”); for (i=0;i=len_num2)? len_num1:len_num2; len_min=(len_num10len_num1–,len_num2–) { sum[len_max--]=((num1[len_num1-1]-’0′)+(num2[len_num2-1]-’ 0′)); } if(len_num10) { sum[len_max--]=num1[len_num1 - 1 ]-’0′; len_num1–; } if(len_num20) { 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; while(sum[j]==0) //跳出头部 0 元素 j++; for(int m=0;mdata=i; head=p; for(i=1;idata=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) { 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); return 0; } 7输入一串字符,只包含”0-10″和”,”找出其中最小的数字和最大的数字 (可能不止一个),输出最后剩余数字个数。如输入 “3,3,4,5,6,7,7″ #include #include #include void main() { char str[100]; printf(“输入一组字符串:\n”); scanf(“%s”, int len=strlen(str); int array[100]; int count=0; for(int i=0;i=’0′ } array[count]=’\0′; int result=count; int min=array[0]; int max=array[0]; for(int j=0;j= 0) { n2 = str2[j--] – ’0′; curSum = n2 + another; result[cur_rs++] = curSum % 10 + ’0′; 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) // str2 { char big[100], small[100]; 使用 str1 减去 int big_len, sml_len; int len1 = strlen(str1); int len2 = strlen(str2); bool flag = false; //用于标记 str2 是否比 str1 大 if(len1 = n2+another) { result[cur_rs++] = (n1-n2-another) +’0′; another = 0; } 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); 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); str2[len2] = ‘\0′; if(str1[0] == ‘-’ 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, str