結果

問題 No.1020 Reverse
ユーザー zeronosu77108
提出日時 2020-04-10 21:45:45
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 1,229 ms
コンパイル使用メモリ 128,976 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-30 17:26:17
合計ジャッジ時間 1,446 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int n,k;
    string s;
    cin >> n >> k >> s;
    
    string ans;
    if (n!=k) {
        for (int i=k-1; i<n; i++) ans += s[i];
        string tmp;
        for (int i=0; i<k-1; i++) tmp += s[i];
        if ((n-(k-1))%2) reverse(tmp.begin(),tmp.end());
        ans += tmp;
    } else {
        ans = s;
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;

    // for (int i=0; i+k-1<n; i++) {
    //     reverse(s.begin()+i, s.begin()+i+k);
    // }
    // cout << s << endl;
}
0