第一次C语言练习赛第20题代码实现
本文最后更新于 2737 天前,其中的信息可能已经有所发展或是发生改变。

内容纲要

[hide]

之前挺多人被这道题卡着,我大概调整了一下代码,现在挂在网站上

第一种方法:

[code lang=”c”]#include <stdio.h>
void ftime(int num,int fcount)
{
if(num=1)
{
printf("%d\n",(fcount+1)*20);
}
else
{
ftime(num/2,++fcount);
}
}
int main()
{
int a;
while(scanf("%d",a)!=EOF)
{
ftime(a,0);
}
return 0;
}
[/code]

这种方法是针对一次输入一次输出的。倘若存在未知数量的输入,应该用以下代码。

第二种方法

 

[code lang=”c”]
#include <stdio.h>
void ftime(int num,int fcount)
{
if(num<=1)
{
printf("%d\n",(fcount+1)*20);
}
else
{
ftime(num/2,++fcount);
}
}
int main()
{
int num[100000],count=0,i=0;
while(scanf("%d",&num[count])!=EOF)
{
count++;
}
for(i=0;i<count;i++)
{
ftime(num[i],0);
}
return 0;
}


[/code]
[/hide]

评论

  1. Ryan
    博主
    Windows Chrome 83.0.4103.61
    4年前
    2020-6-06 17:05:40

    测试评论( 😛

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
下一篇