Yuulis.log

トンネルを抜けるとそこは参照エラーであった。

【AtCoder】ABC 339 A - TLD | 茶コーダーが解くAtCoder

atcoder.jp


実行時間制限: 2 sec / メモリ制限: 1024 MB / Difficulty: 18

問題概要

英小文字と.のみからなる文字列  S が与えられる。  S.で分割したときの末尾の文字列を出力せよ。

制約

  •  S の長さは2以上100以下
  •  S の末尾は.ではない。

考察

問題文がちょっとわかりにくいが、要するに  S の最も後ろにある.から後ろの文字列を出力すればよい。具体的には以下のようになる。

  1.  S の最も後ろにある.のインデックスをidxとする。
  2. S[idx + 1]からS[S.size() - 1]を出力する。

コード

#include <bits/stdc++.h>
using namespace std;

#define rep(i, start, end) for (ll i = (start); i < (ll)(end); i++)

// ======================================== //

int main()
{
    string S;
    cin >> S;

    int idx = 0;
    rep(i, 0, S.size())
    {
        if (S[i] == '.')
            idx = i;
    }

    rep(i, idx + 1, S.size())
    {
        cout << S[i];
    }
    cout << endl;

atcoder.jp


実装時間: 5分以内