//1.字符串比较
int strcmp(char *p1,char *p2)
{
while(*p1 && *p2)
{
if(*p1 != *p2)
{
return *p1-*p2;
}
p1++;
p2++;
}
return 0;
}
//2.闰年计算某天在这年的天数
typedef struct time
{
int year;
int month;
int day;
}TIME;
int runnian(TIME time)
{
int sum = 0;
int n = 29;
if((time.year%4 == 0&& time.year%100 != 0) || time.year%400 == 0) n=28;
switch(time.month)
{
case 12: sum += 31;
case 11: sum += 30;
case 10: sum += 31;
case 9: sum += 30;
case 8: sum += 31;
case 7: sum += 30;
case 6: sum += 31;
case 5: sum += 30;
case 4: sum += 31;
case 3: sum += n;
case 2: sum += 31;
}
sum += time.day;
return sum;
}
//3.打印学生成绩信息
typedef struct student
{
int num;
char name[10];
int score[3];
}STU;
void print(STU *p,int n)
{
if(n==0 || p == NULL) return;
scanf("%d%s%d%d%d",&p->num,p->name,&p->score[0],&p->score[1],&p->score[2]);
print(p+1,n-1);
}
void input(STU stu[],int n)
{
int i;
for(i=0;i<n;i++)
{
printf("%d %s %d %d %d\n",stu[i].num,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2]);
}
}
//4.将13人围成一圈,每报到3那个人退出,输出最后一个人的序号
//非链表方法
int number(int n)
{
int a[n],k= 0,i,m = 0,result;
for(i = 0;i<n;i++) a[i] = 0;
for(i=0;i<n-1;i++)
{
while(k<3)
{
if(a[m] == 0)
{
k++;
}
m++;
m = m%n;
}
a[(m-1+n)%n] = 1;
k = 0;
}
for(i = 0;i<n;i++)
{
if(a[i] == 0) result = i+1;
}
return result;
}
//链表方法
typedef struct human
{
int data;
struct human *next;
}HUMAN,*listlink;
void main()
{
listlink head,p,q;
head = (listlink)malloc(sizeof(HUMAN));
p = head;
int i=1,j;
while(i<13)
{
p->data = i;
q = (listlink)malloc(sizeof(HUMAN));
p->next = q;
p = p->next;
i++;
}
p->data = i;
p->next = head;
for(i=0;i<12;i++)
{
for(j = 0;j<2;j++)
{
p = p->next;
}
q = p->next;
p->next = q->next;
free(q);
}
printf("%d",p->data);
}