本文主要是介绍Throwing cards away I(UVA 10935),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
网址如下:
Throwing cards away I - UVA 10935 - Virtual Judge (vjudge.net)
(第三方网站)
一眼队列啦
倒是输出格式一直没搞好
气死了
代码如下:
#include<queue>
#include<cstdio>
using namespace std;
void throwCards(int n);int main(void)
{int n;while(scanf("%d", &n) == 1 && n)throwCards(n);return 0;
}
void throwCards(int n)
{queue<int> cards;for(int i = 1; i <= n; i++)cards.push(i);printf("Discarded cards:");while(cards.size() > 1){printf("%s%d", (cards.front() == 1) ? " " : ", ", cards.front());cards.pop(); cards.push(cards.front()); cards.pop();}printf("\nRemaining card: %d\n", cards.front());
}
似乎也没必要专门写一个函数
这篇关于Throwing cards away I(UVA 10935)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!