- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我当前的代码:
#include <stdio.h>
#include <string.h>
int main(void)
{
char names[2048][32];
int removed[2048];
int game;
int n;
int m;
int k;
int l;
int i;
int j;
int round;
int pos;
int lowest;
int next;
// Read the number of games to be played
scanf("%d",&n);
// Process each game
for(game = 1; game <= n; game++)
{
// Read the number of friends
scanf("%d",&m);
// Read the names of each friend
for(i=0;i<m;i++)
{
scanf("%s",names[i]);
// Mark the friend as having not been eliminated
removed[i] = 0;
}
// Read the number of rounds and the number of "Ducks"
scanf("%d %d", &k,&l);
// If the number of rounds is greater than the number of friends
// Jimmy will boot all his friends
if(k >= m)
{
printf("Jimmy has friends no more.\n\n");
continue;
}
// Simulate the game round by round
pos = 0;
for(round=0;round<k;round++)
{
// Walk around the circle stopping at the lth remaining friend
for(i=0; i<=l; pos = (pos+1)%m)
{
if(!removed[pos])
i++;
if(i == l+1)
// Give the friend we stopped at the boot
removed[pos]=1;
}
}
lowest = 0;
// Loop for each remaining friend
for(i=0;i<(m-k);i++)
{
// Find the lowest numbered remaining friend
while(removed[lowest])
lowest++;
// Find the friend with the first name alphabetically
next = lowest;
for(j=lowest;j<m;j++)
{
if(!removed[j] && strcmp(names[j],names[next]) < 0)
next = j;
}
// Print the name of the next friend and remove him/her from the circle
removed[next] = 1;
printf("Game %d:\n", game);
printf("%s\n", names[next]);
}
printf("\n");
}
return 0;
}
这是它的输入和输出:
Input:
2
3
Bob
Cody
John
2 2
Game 1: (the output)
Cody(the output)
8
Carol
Casey
Nick
Kirsten
Ben
Bo
Billy
Heather
3 4
Game 2: (The output)
Billy(The output)
Game 2:(The output)
Bo(The output)
Game 2:(The output)
Carol(The output)
Game 2:(The output)
Kirsten(The output)
Game 2:(The output)
Nick(The output)
如何让“Game 2:”printf 语句只显示一次?我尝试将它放在代码的不同部分,但我仍然没有得到它。为了更好地理解我想要得到的东西,这是我想要做的:
Output:
Game 1:
Cody
Game 2:
Billy
Bo
Carol
Kirsten
Nick
最佳答案
将“Game”的打印移至 for
循环之外:
// print "Game" here
printf("Game %d:\n", game);
// Loop for each remaining friend
for(i=0;i<(m-k);i++)
{
// Find the lowest numbered remaining friend
while(removed[lowest])
lowest++;
// Find the friend with the first name alphabetically
next = lowest;
for(j=lowest;j<m;j++)
{
if(!removed[j] && strcmp(names[j],names[next]) < 0)
next = j;
}
// Print the name of the next friend and remove him/her from the circle
removed[next] = 1;
// print "game" was here
printf("%s\n", names[next]);
}
关于c - 打印语句不断打印多次而不是一次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35923060/
如果这不是一个错误,那就是另一个错误。如果不是那样的话,那就是别的东西了。我觉得我的项目已经改变了很多,现在只是试图解决代码签名问题,结果一切都搞砸了。我严格按照说明进行操作,但出现错误,例如当前的“
我不确定是否有一些我不知道的内置变量或规则,或者 make 是否有问题,或者我只是疯了。 对于我的一个项目,我有一个如下的 makefile: CC=g++ CFLAGS=-O3 `libpng-co
我有大约 10 个 div,它们必须不断翻转,每个 div 延迟 3 秒 这个 codrops 链接的最后一个效果是我正在寻找的,但无需单击 div http://tympanus.net/Devel
我如何使用 jQuery 持续运行 PHP 脚本并每秒获取响应,以及将鼠标上的少量数据发送到同一脚本? 我真的必须添加一些随机扩展才能让这么简单的计时器工作吗? 最佳答案 To iterate is
JBoss 4.x EJB 3.0 我见过如下代码(大大简化): @Stateless @TransactionAttribute(TransactionAttributeType.NOT_SUPPO
使用 PHPStorm,我试图忽略每次尝试进行 git 提交时 pop 的 workspace.xml。 我的 .gitignore 看起来像: /.idea/ .idea/workspace.xml
我是一名优秀的程序员,十分优秀!