1、最新最全华为校园招聘软件研发笔试题4 2012最新最全华为校园招聘软件研发笔试题(4) flag = (flag + 1) % 2; p+; printf( n ); return 0; 17、编写一个程序实现功能:将两个字符串合并为一个字符串并且输出,用指针实现。 char str120= Hello , str220= World ; 答案: #include int main() char str120= Hello , str220= World ; char *p=str1, *q=str2; while( *p ) p+; while( *q ) *p = *q; p+; q+;
2、*p = 0 printf( %sn , str1); return 0; 18、算分数的问题,去掉一个最高分一个最低分,求平均分 #include float avescore(float score,int n) float min=0; float max=0; int minindex=0; int maxindex=0; float sum=0; min=score0; for(int i=0;i min=scorei; minindex=i; scoreminindex=0; max=score0; for(i=0;i if(scorei max) max=scorei; maxi
3、ndex=i; scoremaxindex=0; for(i=0;i return sum; void main() float score6=70,80,90,98,87,86; float lastscore; lastscore=avescore(score,6); printf( the last score is :%5.2fn ,lastscore); 运行结果: the last score is :85.75 19、对一个数组,将数组中偶数从大到小排序,奇数从小到大排序,奇数和偶数交叉着放且输出数组第一位放奇数 若奇数和偶数不等长,则把剩下的直接放到数组中。 思路:先进行奇偶判
4、断,得到奇数和偶数数组。然后对两数组排序,进行长度判断,最后组织数据。 #include #include void jiou(int a,int n) int *p1; int *p2; int i,j; int k=0; int kk=0; int count1=0; int count2=0; int temp; int temp2; int m=0; p1=(int*)malloc(sizeof(int)*n); p2=(int*)malloc(sizeof(int)*n); for(i=0;i p1i=0; p2i=0; for(i=0;i if(ai%2)!=0) p2kk+=ai
5、; else p1k+=ai; count1=k; count2=kk; for(i=0;i for(i=0;i for(j=0;jp2j+1) temp2=p2j;p2j=p2j+1;p2j+1=temp2; for(i=0;i for(i=0;i for(i=0;i for(j=0;j temp=p1j;p1j=p1j+1;p1j+1=temp; for(i=0;i if(count1 count2) for(i=0;i ai+m=p2i; ai+1+m=p1i; m=m+1; for(i=0;i for(i=0;i ai+m=p2i; ai+1+m=p1i; m=m+1; for(i=0
6、;i for(i=0;i printf( %3d ,ai); printf( %n void main() int a10=2,3,14,6,2,15,12,14,4,11; jiou(a,10); 运行结果: 3 15 11 3 11 15 2 14 6 2 12 14 4 14 14 12 6 4 2 2 3 14 11 14 15 12 6 4 2 2 20.判断身份证号码的合法性 /*我国公民的身份证号码特点如下: 1、 长度为18位; 2、 第117位只能为数字; 3、 第18位可以是数字或者小写英文字母x。 4、 身份证号码的第714位表示持有人生日的年、月、日信息。 例如:511
7、 002 1988 08 08 0111或511002*。 请实现身份证号码合法性判断的函数。除满足以上要求外,需要对持有人生日的年、月、日信息进行校验。年份大于等于1900年, 小于等于2100年。需要考虑闰年、大小月的情况。 所谓闰年,能被4整除且不能被100整除 或 能被400整除的年份,闰年的2月份为29天,非闰年的2月份为28天。其他情况的合法性校验,考生不用考虑。 函数返回值: 1) 如果身份证号合法,返回0; 2) 如果身份证号长度不合法,返回1; 3) 如果身份证号第117位含有非数字的字符,返回2; 4) 如果身份证号第18位既不是数字也不是英文小写字母x,返回3; 5) 如
8、果身份证号的年信息非法,返回4;6-9 6) 如果身份证号的月信息非法,返回5;10-11 7) 如果身份证号的日信息非法,返回6(请注意闰年的情况);12-13 【注】除成功的情况外,以上其他合法性判断的优先级依次降低。也就是说,如果判断出长度不合法,直接返回1即可,不需要再做其他合法性判断。 #include #include int verifyID(char* inID) int len = strlen(inID); int i; if( len !=18) return 1; for(i=0;i i+) if( *(inID+i) 0 | *(inID+i) 9 ) return
9、2; if( *(inID+17) 0 |*(inID+17) 9 ) if( *(inID+17)!= x ) return 3; char temp110=0; char temp210=0; char temp310=0; memcpy(temp1,inID+6,4); int year=atoi(temp1); if( year 1900|year 2100) return 4; memcpy(temp2,inID+10,2); int mon=atoi(temp2); if( mon 1|mon 12) return 5; memcpy(temp3,inID+12,2); int d
10、ay=atoi(temp3); if(1=mon) if( day 0 |day 31) return 6; if(2=mon)/能被4整除且不能被100整除 或 能被400整除的年份,闰年的2月份为29天,非闰年的2月份为28天。 if( (year%4=0) (year%100!=0) | (year%400=0) ) if( day 0 |day 29) return 6; else if( day 0 |day 28) return 6; if(3=mon) if( day 0 |day 31) return 6; if(4=mon) if( day 0 |day 30) return 6; if(5=mon) if( day 0 |day 31) return 6; if(6=mon) if( day 0 |day 30) return 6; if(7=mon)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1