第1个回答 2014-12-30
#include <stdio.h>
typedef struct child
{
int value; //可爱值
int number; //糖果数量
}Child;
int Check(Child tmp_child[],int x)
{
int j,k,Count = 0;
for(j=0; j < x - 1; j++) // 每次和后面一个孩子进行比较
{
if(tmp_child[j].value < tmp_child[j+1].value){
tmp_child[j+1].number += 1;
}else if(tmp_child[j].value > tmp_child[j+1].value){
tmp_child[j].number += 1;
}else{
printf("Nothing we can do\n");
}
}
return Count;
}
int main()
{
printf("Please input the number of Childs:");
int n = 0;
int count= 0;
scanf("%d",&n);
Child t_child[n];
int i = 0;
for(; i < n; i++) //初始化
{
scanf("%d",&t_child[i].value);
t_child[i].number = 1;
}
count = Check(t_child,n);
if(count <= n)
{
printf("Need to be check the function!!\n");
}
printf("The number is less than: %d\n",count);
return 0;
}
调试结果:
Please input the number of Childs:5
3
40
2
1
10
The number is less than: 9