#UVa:12554-A Special “Happy Birthday” Song!!!

灆洢 2019-04-12 00:42:47

從人數與生日快樂歌的單詞個數先算出最少要唱完整的幾遍才會讓所有人都唱過,之後利用算出來的個數列印出答案即可。

C++(0.000)

/*******************************************************/
/* UVa 12554 A Special "Happy Birthday" Song!!!        */
/* Author: Maplewing [at] knightzone.studio            */
/* Version: 2019/04/12                                 */
/*******************************************************/
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

int main(){
  const string HAPPY_BIRTHDAY_SONG[] = {
    "Happy", "birthday", "to", "you",
    "Happy", "birthday", "to", "you",
    "Happy", "birthday", "to", "Rujia",
    "Happy", "birthday", "to", "you"
  };
  const int HAPPY_BIRTHDAY_SONG_WORD_COUNT = 16;

  int n;
  while(scanf("%d", &n) != EOF){
    vector<string> names(n);
    for(int i = 0 ; i < n ; ++i){
      cin >> names[i];
    }

    int times = n / HAPPY_BIRTHDAY_SONG_WORD_COUNT + ((n % HAPPY_BIRTHDAY_SONG_WORD_COUNT == 0)? 0 : 1);
    for(int i = 0 ; i < times ; ++i){
      for(int j = 0 ; j < HAPPY_BIRTHDAY_SONG_WORD_COUNT ; ++j){
        int nameIndex = (i * HAPPY_BIRTHDAY_SONG_WORD_COUNT + j) % n;
        printf("%s: %s\n", names[nameIndex].c_str(), HAPPY_BIRTHDAY_SONG[j].c_str());
      }
    }
  }
  return 0;
}

發表迴響

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料