1.编写程序,输入一个月份,输出对应的英文名称
#include<stdio.h>
#include <stdlib.h>
int main()
{
printf(“请输入月份\n”);
int n; scanf("%d",&n);
char month[]= {“January”, “February”, “March”, “April”, “May”, “June”, “July”,“August”, “September”, “October”, “November”, “December”};
if(n<1||n>12)
{
printf(“输入月份错误\n”);
}
else
{
printf("%s",(month+n-1));
}
return 0;
}
2. 输入一个字符串,在表中查找,输出该字符串在表中的序号
#include<stdio.h>
#include<string.h>
int main()
{
int i,ri,repeat;
char *date[]={“Sunday”,“Monday”,“Tuesday”,“Wednesday”,“Thursday”,“Friday”,“Saturday”};
char str[80];
scanf("%d",&repeat); getchar();
for(ri=1;ri<=repeat;ri++)
{
scanf("%s",str);
}
for(i = 0; i < 7; i++)
{
if(strcmp(str, date[i]) == 0)
{
printf("%d\n", i+1);
break;
}
if(i == 7)
{
printf("-1\n");
}
return 0;
}
3. 编写程序,输入 n(n<10)个字符,输出其中最长字符串的有效长度
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int max_len(char *s[] , int n);
int main()
{
char **s;
int n, i;
scanf("%d", &n);
s=(char **)malloc(n * sizeof(char *));
for(i=0;i<n;i++)
s[i]=(char *)malloc(sizeof(char)*20);
for(i=0;i<n;i++)
{
scanf("%s", s[i]);
}
printf("%d", max_len(s, n));
return 0;
}
int max_len(char *s[] , int n)
{
int i, max=0;
for(i=0;i<n;i++)
{
if(strlen(s[i])>max)
max=strlen(s[i]);
}
return max;
}
4. 输入若干个学生信息(包括学号、姓名和成绩),输入学号为 0 时输入结束,建立一个单向链表,再输入一个成绩值,将成绩大于等于该值的学生信息输出
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct stud_node
{
int num;
char name[20];
int score;
struct stud_node *next;
};
struct stud_node *Creat_Stu_Doc(); struct stud_node *DeleteDoc(struct stud_node *head,int min_score); void Ptrint_Stu_Doc(struct stud_node *head); int main(){struct stud_node *head; int min_score;head=Creat_Stu_Doc(); scanf("%d",&min_score); head=DeleteDoc(head,min_score); Ptrint_Stu_Doc(head); return 0;}struct stud_node *Creat_Stu_Doc(){struct stud_node *head,*tail, *p; int num, score; char name[20]; int size = sizeof(struct stud_node);head=tail=NULL; scanf("%d",&num); while(num != 0){ scanf("%s%d",name,&score); p=(struct stud_node*)malloc(size); p->num=num; strcpy(p->name,name); p->score=score; p->next=NULL; if(head==NULL) head=p; else tail->next=p; tail=p; scanf("%d",&num);}return head;}struct stud_node *DeleteDoc(struct stud_node *head,int min_score){struct stud_node*ptr1,*ptr2;while(head!=NULL&&head->score<min_score){ ptr2=head; head=head->next; free(ptr2);}if(head==NULL) return NULL; ptr1=head; ptr2=head->next; while(ptr2!=NULL){ if(ptr2->score<min_score){ ptr1->next=ptr2->next; free(ptr2); } else ptr1=ptr2; ptr2=ptr1->next;}return head;}void Ptrint_Stu_Doc(struct stud_node *head){struct stud_node*ptr;if(head==NULL){ printf("\nNo Records\n"); return;}for(ptr=head; ptr; ptr=ptr->next){ printf("%d %s %d\n", ptr->num,ptr->name,ptr->score);}