# 姓名縮寫 https://neoj.sprout.tw/problem/894/ ### 題目敘述 外國人很多名字很長,叫起來很不方便,所以需要縮寫。 現在給你某人的全名(first name + last name)和簡寫的字母數,請用一個字呼喚他的簡稱三次。 ### 輸入 第一行是兩個字串 $f$, $l$,代表一個全名 第二行有兩個數字 $m$, $n$,代表簡稱取自開頭的字數。 ### 輸出 請輸出三行,每行皆為 $f$ 的前 $m$ 個字母接 $l$ 的前 $n$ 個字母 。 ### 輸入限制 $1 ≤ |f|,\ |l| ≤ 100$ $1 ≤ m ≤ |f|,\ 1≤ n ≤ |l|$ ### 範例輸入輸出 #### 範例輸入 I ``` string length 3 3 ``` #### 範例輸出 I ``` strlen strlen strlen ``` #### 範例輸入 II ``` coronary virusCleaner 6 5 ``` #### 範例輸出 II ``` coronavirus coronavirus coronavirus ``` ### Hint 使用 strncpy, strncat # Code ```cpp #include <iostream> #include <cstring> using namespace std; int main(){ char f[250], l[110]; int a, b; cin >> f >> l >> a >> b; f[a] = '\0'; l[b] = '\0'; strcat(f, l); for (int t = 1; t <= 3; t++) cout << f << "\n"; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up