1
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?

【APG4b - AtCoder C++】ABC049居合を終え、青い絵を覆う

Last updated at Posted at 2024-03-06

AtCoder 学習記録用 (APG4b)ABC049

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

int main(){
  char c;
  bool judge = false;
  cin >> c;
  //解法1
  // if( (c == 'a') || (c == 'i') || (c == 'u') || (c=='e') || (c =='o') ){
  //   judge = true;
  // }
  //解法2
  string vowel = "aiueo";
  for(int i=0; i < vowel.size(); i++){
    if(c == vowel.at(i)){
      judge = true;
      break;
    }
  }
  
  if(judge){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}
  • 今回学んだこと
    解法1のときに、a,i,u,e,oをそれぞれダブルクオーテーションでくくると、char型ではなく、文字列型になり、エラーがでる。if文の条件丸カッコで丁寧に丸括弧をたくさん書いているが、なくてもよし。

  • string型でaiueoを変数に格納して、at()で取り出せばchar型として比較できる。私は最初vowel[]={a,i,...}でchar型の配列を使って解こうとしたんてすが、途中で分からなくなり、ピボットしました。。

1
0
3

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
1
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?