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 5 years have passed since last update.

ABC071-B

Last updated at Posted at 2019-05-28

ABC071B B - Not Found
与えられた小文字からなる文字列のうち、出てきていないアルファベットで一番自書式配列で早いものを出力する。
まず入力された文字列を最初から読んでいく。その時そのアルファベットに対応する箇所(例えばaなら1,bなら2,...)をカウントするvector cnt(100)を用意する。
最終的に文字列を最後まで読み終わった後、cnt(100)について、アルファベットは26なので、最初から見ていって、最初に0が来る数字を選んで、それに対応するアルファベットを出力する。
zまで、つまりi=25が終わるまで0が出ないときは、"None"と出力する。:relaxed:

aからi番目のアルファベットを出力するには(aを0番目として)

char ans=i+'a';

とした。

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

int main() {
 string s;cin >>s;
  vector<int> cnt(100);//この時アルファベットが何個あるか知らなかったので適当に100と置いた
  for(int i=0;i<s.size();i++){
   int al=s[i]-'a';//b->1,d->3...というようにintで置いておく。
   cnt[al]++;
  }
  int stl=0;
  for(int i=0;i<26;i++){
   if(cnt[i]==0){
    char ans=i+'a';
     cout << ans << endl;
     return 0;
   }
   else stl++;//stlはsteam locomotive の略。
  }

  if(stl==26)cout << "None" << endl;
}

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?