码迷,mamicode.com
首页 > 其他好文 > 详细

百度模拟笔试-2016.04.19

时间:2016-04-20 13:43:16      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

 

技术分享

// INCLUDE HEADER FILES NEEDED BY YOUR PROGRAM

// SOME LIBRARY FUNCTIONALITY MAY BE RESTRICTED

// DEFINE ANY FUNCTION NEEDED

// FUNCTION SIGNATURE BEGINS, THIS FUNCTION IS REQUIRED

#include<iostream>

#include<string.h>

 

 

using namespace std;

 

int canArrangeWords(int num,char** arr){

// WRITE YOUR CODE HERE

char *a=(char *)malloc(num*sizeof(char));

char *b=(char *)malloc(num*sizeof(char));

int *c=(int *)malloc(num*sizeof(int));

for(int i=0;i<num;i++){

int len=strlen(arr[i]);

a[i]=arr[i][0];

b[i]=arr[i][len-1];

c[i]=1;

}

int count=num;

for(int j=1;j<num&&c[j]==1;j++){

if(a[0]==b[j]){

a[0]=a[j];

c[j]==0;

count--;

}else if(b[0]==a[j]){

b[0]=b[j];

c[j]==0;

count--;

}

}

free(a);

free(b);

free(c);

if(count==1){

return 1;

}else

return -1;

}

// FUNCTION SIGNATURE ENDS

 

// DO NOT IMPLEMENT THE main( ) METHOD

 

技术分享

// INCLUDE HEADER FILES NEEDED BY YOUR PROGRAM

// SOME LIBRARY FUNCTIONALITY MAY BE RESTRICTED

// DEFINE ANY FUNCTION NEEDED

// FUNCTION SIGNATURE BEGINS, THIS FUNCTION IS REQUIRED

#include<iostream>

using namespace std;

int perfectNumberCheck(int num)

{

int i,sum=0;

for(i=1;i<=num/2;i++){

if(num%i==0)

sum+=i;

}

if(sum==num)

return 1;

else

return 0;

// CHECK WHETHER NUMBER IS PERFECT OR NOT

// RETURN RESULT

// WRITE YOUR CODE HERE

}

// FUNCTION SIGNATURE ENDS

 

// DO NOT IMPLEMENT THE main( ) METHOD

百度模拟笔试-2016.04.19

标签:

原文地址:http://www.cnblogs.com/Pumpkinandy/p/5412056.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!