⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 15个美国人和15个日本人.cpp

📁 //一个笔试题:15个美国人和15个日本人围坐一圈
💻 CPP
字号:
//一个笔试题:15个美国人和15个日本人围坐一圈,从其中一人开始数数,从1数到9,数到9的人踢出去,
//设计代码使被踢出的人都是日本人,输出日本人坐的位置。

#include <iostream>
using namespace std;

struct person
{
    int position;

    bool needRemove; //Japanese will be removed
    person *next;
};
void main()
{
    person sp[30];
	cout<<sizeof(sp)<<"\n";
	cout<<sizeof(person)<<"\n";
	cout<<sizeof(bool)<<"\n";

    for(int i=0; i<30;i++)
    {
        sp[i].position=i;
        sp[i].needRemove=false;
		cout<<sp[i].position<<"  ";
        if(i==29)
        {
            sp[i].next=sp;
        }
        else
        {
            sp[i].next=&sp[i+1];
        }
    }//finish the circal link table
	person *pos1=sp;
	cout<<"\n";
for(i=0;i<35;i++)
{
	cout<<pos1->position<< "  ";
	pos1=pos1->next;
	
}
    cout<<"\n";
    person *pos=sp;
    int it=0, total=0;
    while(total<15)
    {
        if(pos->needRemove!=true)
        {
            it++;
            if(it==9)
            {
                cout<<pos->position<<endl;
                pos->needRemove=true;
                total++;
                it=0;
            }
        }
        pos=pos->next;
    }
//    return 0;
}


//文章出处:http://www.diybl.com/course/3_program/c++/cppsl/2008227/101919.html

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -