# 第三次作业

## pta第三次作业(1)6-1 输出月份英文名

### 2.实验代码

char *getmonth( int n )
{
switch (n){
case 1:return "January";break;
case 2:return "February";break;
case 3:return "March";break;
case 4:return "April";break;
case 5:return "May";break;
case 6:return "June";break;
case 7:return "July";break;
case 8:return "August";break;
case 9:return "September";break;
case 10:return "October";break;
case 11:return "November";break;
case 12:return "December";break;
default:return NULL;
}

}


## pta第三次作业(1)6-2 查找星期

### 2.实验代码

    int getindex(char *s)
{
int i;
char day[7][10] = { "Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday" };
for (i = 0; i <= 6; i++)
{
if (strcmp(s, day[i]) == 0) break;
}
if (i == 7) i = -1;
return i;
}


## pta第三次作业(1)计算字符串长度

### 2.实验代码

int max_len( char *s[], int n )
{
int i,a;
int max=strlen(s[0]);
for(i=1;i<n;i++){
a=strlen(*(s+i));
if(a>max)
max=a;
}
return max;
}


## pta第三次作业(1)

### 2.实验代码

char *match( char *s, char ch1, char ch2 ){

int i=0,j=0,k=0,len=0;
char *p=NULL;

len = strlen(s);

for(i=0;i<len;i++){
if(s[i]==ch1){
p=&s[i];
for(j=i;j<len;j++){
if(s[j]!=ch2){
printf("%c", s[j]);
}
if(s[j]==ch2){
printf("%c\n", s[j]);
return p;
}
}
printf("\n");
return p;
}
}
printf("\n");
return p;
}


## pta第三次作业(2)奇数值结点链表

### 2.实验代码

struct ListNode *readlist(){
int data;
p=q=(struct ListNode *)malloc(sizeof(struct ListNode));
scanf("%d",&p->data);
while(p->data!=-1){
}else{
q->next=p;
}
q=p;
p=(struct ListNode *)malloc(sizeof(struct ListNode));
scanf("%d",&p->data);
}
q->next=NULL;
}
struct ListNode *getodd( struct ListNode **L ){
if(*L!=NULL){
if(h==NULL){
}else{
}
}else{
if(q==NULL){
}else{
}
}
}
p->next=NULL;
if(m!=NULL)
m->next=NULL;
*L=q;
}else{
return NULL;
}
return(h);
}


## pta第三次作业(2)6-2 学生成绩链表处理

### 2.实验代码

       struct stud_node *createlist(){
p=ptr=(struct stud_node *)malloc(sizeof(struct stud_node));
int num;
char name[20];
int score;
scanf("%d",&p->num);
while(p->num!=0){
scanf("%s %d",p->name,&p->score);
}else{
p->next=p;
}
ptr=p;
p=(struct stud_node *)malloc(sizeof(struct stud_node));
scanf("%d",&p->num);
}
ptr->next=NULL;
}
struct stud_node *deletelist( struct stud_node *head, int min_score ){
struct stud_node *p,*ptr,*a;
int i;
if(p!=NULL){
while(min_score<=p->score&&p->next!=NULL){
ptr=p;p=p->next;
}
if(min_score>p->score){
}else{
ptr->next=p->next;
}
}
}
}
}


## pta第三次作业(2)6-3 链表拼接

### 2.实验代码

struct ListNode *mergelists(struct ListNode *list1, struct ListNode *list2)
{
int num = 0;
int temp[100];
struct ListNode *p = list1;
while(p != NULL)
{
temp[num] = p->data;
num++;
p = p->next;
}
p = list2;
while(p != NULL)
{
temp[num] = p->data;
num++;
p = p->next;
}
int i,j;
for(i = 0; i < num; i++)
for(j = i + 1; j < num; j++)
{
if(temp[i] > temp[j])
{
int t;
t = temp[i];
temp[i] = temp[j];
temp[j] = t;
}
}
struct ListNode *newlist = NULL;
struct ListNode *endlist = NULL;
struct ListNode *q;
for(i = 0; i < num; i++)
{
q = (struct ListNode *)malloc(sizeof(struct ListNode));
q->data = temp[i];
if(newlist == NULL)
{
newlist = q;
newlist->next = NULL;
}
if(endlist != NULL)
{
endlist->next = q;
}
endlist = q;
endlist->next = NULL;
}
return newlist;
}

posted @ 2018-04-15 19:50  李新华  阅读(263)  评论(10编辑  收藏  举报