題目:過生日唱生日歌,每人唱一二個單詞,每個人都要至少唱一個單詞,
最後停止時要正好唱完一個循環。
分析:簡單題,模擬輸出即可,設置一個標誌位,所有人唱完標誌成1,
每次唱完一個循環就判斷是否結束即可。
說明:600題還很遙遠╮(╯▽╰)╭。
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespace std; char name[101][101]; char song[16][9] = { "Happy","birthday","to","you", "Happy","birthday","to","you", "Happy","birthday","to","Rujia", "Happy","birthday","to","you"}; int main() { int n; while (~scanf("%d",&n)) { for (int i = 0 ; i < n ; ++ i) scanf("%s",name[i]); int flag = 0,sing = 0,now = 0; while (!flag || sing) { printf("%s: %s\n",name[now],song[sing]); sing = (sing+1)%16; if (++ now == n) { now = 0; flag = 1; } } } return 0; }
UVa 12554 - A Special "Happy Birthday" Song!!!
原文:http://blog.csdn.net/mobius_strip/article/details/44067427