uva10935 - Throwing cards away I
2015-02-11 02:36
337 查看
#include<iostream> #include<vector> using namespace std; int n; vector<int> cards; int main() { while(cin >> n && n){ int first = 1; for(int i = 1; i <= n; i++) cards.push_back(i); cout << "Discarded cards:"; while(!cards.empty()){ if(cards.size() == 1) break; if(first){ first = 0; cout << " "; }else cout << ", "; cout << cards[0]; cards.erase(cards.begin()); cards.push_back(cards[0]); cards.erase(cards.begin()); } cout << endl; cout << "Remaining card: " << cards[0] << endl; cards.clear(); } return 0; }
上面是用不定长数组做的。下面稍微一改是队列写的:
<pre name="code" class="cpp">#include<iostream> #include<queue> using namespace std; queue<int> cards; int n; int main() { while( cin >> n && n ){ for(int i = 1; i <= n ; i++) cards.push(i); cout << "Discarded cards:"; int first = 1; while( !cards.empty() ){ if( cards.size() == 1) break; if(first) { first = 0; cout << " "; } else cout << ", "; cout << cards.front(); cards.pop(); cards.push(cards.front()); cards.pop(); } cout << endl << "Remaining card: " << cards.front() << endl; while( !cards.empty() ){ cards.pop(); } } return 0; }
相关文章推荐
- UVa-10935 - Throwing cards away I
- UVA - 10935 Throwing cards away I (数组)
- UVA 10935 Throwing cards away
- uva-10935-Throwing cards away I
- Uva - 10935 - Throwing cards away I
- UVA10935 Throwing cards away I【模拟+queue+循环队列】
- UVa 10935 Throwing cards away I【队列模拟】
- UVa 10935 Throwing cards away I(习题5-3)
- Uva - 10935 - Throwing cards away I
- 【习题5-3 UVA-10935】Throwing cards away I
- 习题5-3 UVA 10935 Throwing cards away I 卡片游戏
- UVa 10935 - Throwing cards away I
- UVA - 10935 Throwing cards away I
- Uva10935 - Throwing cards away I
- uva 10935 Throwing cards away I
- 经典第五章 习题 5-3 UVA 10935 Throwing cards away I(队列的简单应用)
- UVa 10935 Throwing cards away I
- UVa 10935 (水题) Throwing cards away I
- (1.1.7)UVA 10935 Throwing cards away I(直叙式模拟)
- UVa 10935 - Throwing cards away I