首页 > 其他分享 >13个人报数数到3退出最后剩谁

13个人报数数到3退出最后剩谁

时间:2024-05-24 16:09:26浏览次数:14  
标签:13 struct int 数数 next num 退出 head Man

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
struct Man{
    int num;
    struct Man *next;
};

void LastRemain(int num,int count);
 int main(){
 LastRemain(13,3);
 }
void LastRemain(int num,int count){
    
    if(count==1){printf("the result is %d",num);return;}
    
    struct Man * head=(struct Man *)malloc(sizeof(struct Man));
    head->num=0;
    struct Man *p=head,*q;
    int i;
    for(i=0;i<num;i++){
        p->next=(struct Man *)malloc(sizeof(struct Man));
        p=p->next;
        p->num=i+1;
        p->next=NULL;
    }

    p->next=head->next;
    p=head->next;
    q=head;
    i=1;
    while(p->next!=p){
        if(i==count){
            printf("delete %d\n",p->num);
            q->next=p->next;
            free(p);
            p=q;
            i=0;
        }

        i++;
        q=p;
        p=p->next;

    }

    printf("the last man is %d",p->num);

    free(head);
    free(p);
}


标签:13,struct,int,数数,next,num,退出,head,Man
From: https://www.cnblogs.com/zhongta/p/18211154

相关文章

  • 139-Word Break
    问题描述GivenastringsandadictionaryofstringswordDict,returntrueifscanbesegmentedintoaspace-separatedsequenceofoneormoredictionarywords.Notethatthesamewordinthedictionarymaybereusedmultipletimesinthesegmentation.解释......
  • [lnsyoj121/luoguP4513]小白逛公园
    题意原题链接给定序列\(a\),要求处理单点修改和查询区间最大子段和sol单点修改,区间查询,考虑线段树UPDATE操作对于一个区间,其最大子段和的位置只会有三种情况:在左子区间在右子区间在左右两区间都有如果是前两种情况,那么答案就是对应子区间的最大子段和如果是第三种情况......
  • 编译安装pcre2-10.39 zlib-1.3.1 openssl-3.0.13
    #!/bin/bash#auth:chenjf#func:installnginxstandalone#version:v2.0#sys:CentOSLinuxrelease7.9.2009(Core)#installerversion:pcre2-10.39zlib-1.3.1openssl-3.0.13PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin##要用root安装[$......
  • 编译安装nginx 1.26.0、openssl 3.0.13 常见报错
    报错1[[email protected]]#./config--prefix=/usr/local/openssl--openssldir=/usr/local/opensslsharedCan'tlocateIPC/Cmd.pmin@INC(@INCcontains:/root/nginx-install/openssl-3.0.13/util/perl/usr/local/lib64/perl5/usr/lo......
  • 百问网,T113 usb摄像头使用cpu解码显示
    1资料下载https://download.100ask.net/boards/Allwinner/T113/index.html2软件安装资料下载完毕后,根据说明,安装vmware,安装win驱动3配置开发环境为了方便,建议将sdk文件上传到目录/home/book/安装必要的工具包,如果出现问题Couldnotgetlock/var/lib/dpkg/lock-......
  • 20211317李卓桐 Exp7 网络欺诈防范 实验报告
    Exp7网络欺诈防范基础问题回答(1)通常在什么场景下容易受到DNSspoof攻击DNSspoof攻击,也称为DNS欺骗或DNS欺瞒,是一种网络攻击手法,其中攻击者通过伪造DNS(域名系统)应答来误导互联网用户,使得他们访问恶意网站或服务器,而不是他们原本想要访问的真实网站或服务。以下场景可能会容易......
  • AP2813双路降压恒流LED芯片_外围简单内置功率管驱动IC
    产品叙述AP2813是深圳市世微半导体有限公司推出的一款双路降压恒流驱动器,高效率、外围简单、内置功率管,适用于5-80V输入的高精度降压LED恒流驱动芯片。内置功率管输出大功率可达12W,最大电流1.2A。AP2813一路直亮,另外一路通过MODE1切换全亮,爆闪。AP2813工作频率固定在......
  • 引燃算力新基建,天翼云亮相DCIC2024第13届数据中心产业发展大会!
    近日,由中国通信企业协会主办的“第13届数据中心产业发展大会暨AIDC智能算力生态合作展览会”在北京顺利举行。现场展示了天翼云“AIDC”“紫金”“云骁”“息壤”等技术和平台能力;中国电信天翼云2023年智算资源池上海节点建设工程获得大会“算力基础设施高质量发展企业案例奖”;天......
  • CVE-2018-12613
    phpmyadmin4.8.1RemoteFileInclusionVulnerability(CVE-2018-12613)PhpMyAdminisafreesoftwaretoolwritteninPHP,intendedtohandletheadministrationofMySQLovertheWeb.Thevulnerabilityisintheindex.php,causingfilesiclusionvulnerabili......
  • P10513 括号
    P10513括号一、题目简析本题采用线段树求解。节点的定义structnode{ intl,r; intlcnt,rcnt;//lcnt--(的个数;rcnt--)的个数 intans,anti;//ans--()的个数;anti--)(的个数 booltag;//true--需要翻转左右孩子}tree[N......