标签:
// 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
标签:
原文地址:http://www.cnblogs.com/Pumpkinandy/p/5412056.html