【十二月】第一次课堂练习

P1996

#include<stdio.h>
#include<stdlib.h>
struct people
{
    int num;
    struct people *next;
    
};
int main()
{
    struct people *head,*t,*s,*p;
    head=(struct people*)malloc(sizeof(struct people));
    head->next=NULL;
    int n,m;
    scanf("%d %d",&n,&m);
    int i;
    for(i=1;i<=n;i++)
    {
        t=(struct people*)malloc(sizeof(struct people));
        t->num=i;
        if(head->next==NULL)
        head->next=t;
        else s->next=t;
        
        s=t;
    }
    
    s->next=head->next;//头尾相连
    p=head;
    while(p->next!=p)//删到只剩下一个人的时候 
    {
        for(i=0;i<m-1;i++)//走着走着走到m的前一个,将m的序号打出来再将m跳过 
        {
            p=p->next;
        }
        printf("%d ",p->next->num);
        p->next=p->next->next;
    }
    
    //最后再将最后一个人的序号打出来
    printf("%d",p->num);
    
    return 0; 
}
View Code

 P1241

#include<cstdio>
#include<cstring>
int  q[101],top;
char c[101],b[101];
int main()
{
    int i,l;
    scanf("%s",c);
    l=strlen(c); 
    for (i=0;i<l;i++)
    {
        if (c[i]=='(') {q[++top]=i; b[i]=')';}
        if (c[i]=='[') {q[++top]=i; b[i]=']';}
        if (c[i]==')'||c[i]==']') 
            if (!top||b[q[top]]!=c[i])
                if (c[i]==')') b[i]='('; else b[i]='[';
            else b[q[top--]]=' ';
    }
    for (i=0;i<l;i++)
    {
        if (b[i]=='('||b[i]=='[') printf("%c",b[i]);
        printf("%c",c[i]);
        if (b[i]==')'||b[i]==']') printf("%c",b[i]);
    }
    return 0;
}
View Code

 

posted @ 2021-12-04 10:55  Oranges  阅读(80)  评论(0编辑  收藏  举报