0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[Atcoder備忘録記事]AtCoder Beginner Contest 344 A問題

Posted at

AtCoder Beginner Contest 344 A問題
こちらの問題を解いたので、備忘録用の記事です。

問題

image.png

入出力例

image.png

解法

この問題は"|"で囲まれている部分を削除して出力するというものです。
そのままSをforループで回すことでとけます。

#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>
#include <cmath> 
#include <algorithm>
using namespace std;

int main() {
    string S;
    string ans = "";
    bool flag = false;
    cin >> S;
    for(int i = 0; i < S.length(); i++){
        if(S[i] == '|') flag = !flag;
        else if(!flag) ans += S[i];
    }

    cout << ans << endl;
    return 0;
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?