---
# System prepended metadata

title: 1122 程式設計實習IV (資訊一乙) Week03 作業
tags: [程式設計 IV]

---

# 1122 程式設計實習IV (資訊一乙) Week03 作業

## 1. Happy Number

---

### 題目敘述

Let the sum of the square of the digits of a positive integer $S_0$ be represented by $S_1$. In a similar way, let the sum of the squares of the digits of $S_1$ be represented by $S_2$ and so on. If $S_i$ = 1 for some $i \le 1$, then the original integer $S_0$ is said to be Happy number. A number, which is not happy, is called Unhappy number. For example 7 is a Happy number since 7 → 49 → 97 → 130 → 10 → 1 and 4 is an Unhappy number since 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4.

---

### 題目輸入

The input consists of several test cases, the number of which you are given in the first line of the input. Each test case consists of one line containing a single positive integer $N$ smaller than $10^9$.

---

### 題目輸出

For each test case, you must print one of the following messages:

- Case #$p$: $N$ is a Happy number.
- Case #$p$: $N$ is an Unhappy number.

Here $p$ stands for the case number (starting from $1$). You should print the first message if the number $N$ is a happy number. Otherwise, print the second line.

---

### 範例輸入

```
3
7
4
13
```

---

### 範例輸出

```
Case #1: 7 is a Happy number.
Case #2: 4 is an Unhappy number.
Case #3: 13 is a Happy number.
```

---

## 2. Mischievous Children

---

### 題目敘述

Adam’s parents put up a sign that says “CONGRATULATIONS”. The sign is so big that exactly one letter fits on each panel. Some of Adam’s younger cousins got bored during the reception and decided to rearrange the panels. How many unique ways can the panels be arranged (counting the original arrangement)?

---

### 題目輸入

The first line of input is a single non-negative integer. It indicates the number of data sets to follow.
Its value will be less than 30001.
Each data set consists of a single word, in all capital letters.
Each word will have at most 20 letters. There will be no spaces or other punctuation.
The number of arrangements will always be able to fit into an unsigned long int. Note that 12! is the largest factorial that can fit into an unsigned long int.

---

### 題目輸出

For each word, output the number of unique ways that the letters can be rearranged (counting the original arrangement). Use the format shown in Sample Output, below.

---

### 範例輸入

```
3
HAPPY
WEDDING
ADAM
```

---

### 範例輸出

```
Data set 1: 60
Data set 2: 2520
Data set 3: 12
```

---


## 作業繳交方式

- 交至ilearn作業繳交區
- 原始碼檔名以 學號_題號.c 或 學號_題號.cpp 命名 (example. D1109070_01.c 或是 D1109070_01.cpp)
- 兩題分兩個檔案上傳
- 在OJ上面有可以讓你檢視是否正確的作答區
    - 名稱: [112 (資訊一乙) 程式設計IV Week03 作業]
    - 密碼: DEFCON