当前位置:网站首页>[pointer] solve the last person left
[pointer] solve the last person left
2022-07-06 14:36:00 【|Light|】
requirement
Yes n A circle of individuals , Sequence number . Count from the first person , Where to report 3 Of the people out of the circle , Make up a function , The last thing left is the original number .( Use a pointer to achieve )
Code
/* * This function is used to calculate the last remaining bit * n: The number of people in the enclosure * Return its number */
int last_one(int n)
{
int k=-1;
int i,j,l=0;
int a[n];
for(i=0;i<n;i++)
{
a[i] = 0;
}
for(i=0;i<n-1;i++)
{
for(j=0;j<3;j++)
{
if(a[l]==1)
{
j--;
l++;
if(l==n)
{
l=0;
}
continue;
}
if(j==2)
{
a[l]=1;
}
l++;
if(l==n)
l=0;
}
}
for(i=0;i<n;i++)
{
if(a[i]==0)
{
k = i+1;
break;
}
}
return k;
}
main function
int main()
{
int n;
scanf("%d",&n);
printf("%d\n",last_one(n));
return 0;
}
test
Test input
3
Output
2
边栏推荐
- The most popular colloquial system explains the base of numbers
- 【指针】统计一字符串在另一个字符串中出现的次数
- XSS (cross site scripting attack) for security interview
- DVWA (5th week)
- Data mining - a discussion on sample imbalance in classification problems
- 函数:求方程的根
- 指針:最大值、最小值和平均值
- 《統計學》第八版賈俊平第七章知識點總結及課後習題答案
- [issue 18] share a Netease go experience
- Statistics 8th Edition Jia Junping Chapter IX summary of knowledge points of classified data analysis and answers to exercises after class
猜你喜欢
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
《統計學》第八版賈俊平第七章知識點總結及課後習題答案
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
Internet Management (Information Collection)
Matplotlib绘图快速入门
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
Statistics 8th Edition Jia Junping Chapter 14 summary of index knowledge points and answers to exercises after class
Library management system
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
随机推荐
JDBC看这篇就够了
Realize applet payment function with applet cloud development (including source code)
Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
Library management system
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
The most popular colloquial system explains the base of numbers
This article explains in detail how mockmvc is used in practical work
《统计学》第八版贾俊平第六章统计量及抽样分布知识点总结及课后习题答案
《英特尔 oneAPI—打开异构新纪元》
《统计学》第八版贾俊平第二章课后习题及答案总结
List and data frame of R language experiment III
指针 --按字符串相反次序输出其中的所有字符
Functions: Finding Roots of equations
内网渗透之内网信息收集(四)
《统计学》第八版贾俊平第四章总结及课后习题答案
指針:最大值、最小值和平均值
【指针】统计一字符串在另一个字符串中出现的次数
【指针】求二维数组中最大元素的值
《统计学》第八版贾俊平第五章概率与概率分布
Mysql的事务是什么?什么是脏读,什么是幻读?不可重复读?