UVA 11192 - Group Reverse 題目: Group reversing a string means reversing a string by groups. 以下為範例 "TOBENUMBERONEWEMEETAGAINANDAGAINUNDERBLUEICPCSKY" 此字串長度為48,假設我們把該字串分成8個長度為6的群組,對每個群組內的字串分別做反轉,會得到另一個新字串: "UNEBOTNOREBMEEMEWENIAGATAGADNAEDNUNIIEULBRYKSCPC" 此行為就稱為Group reversing。 給定群組數目及字串,請你分組反轉字串。 Input 每行包含一個整數G (G < 10),表示群組數,當G為0代表輸入結束 接著是一個字符串,其長度為G的倍數。 字符串長度不大於100。 字符串僅包含英文字母。 Output 對於每一行輸入,輸出此字符串的Group reversing。 Sample Input #1 3 ABCEHSHSH 5 FAOETASINAHGRIONATWONOQAONARIO 0 Sample Output #1 CBASHEHSH ATEOAFGHANISTANOIRAQONOWOIRANO C++ code: ```c++= #include <bits/stdc++.h> #define speed ios::sync_with_stdio(0);cin.tie(0); #define ll long long int using namespace std; int main() { int n; string s; while (cin >> n) { if (n == 0) break; else { cin >> s; vector<string> word; int len = s.length() / n; for (int i = 0; i < s.length(); i += len) { string ans = s.substr(i, len); reverse(ans.begin(), ans.end()); word.push_back(ans); } for (string c : word) { cout << c; } cout << endl; } } } ```
×
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