元Webデザイナー兼コーダーの備忘録

ウェブデザインやプログラミング、ブログのカスタマイズなどについてアウトプットしています。

 メニュー

» HTML入門のまとめはこちらです。

AtCoder:ABC059:A - Three-letter acronym

AtCoderの過去問対策です。ABCで解けなかった問題、ためになった問題のコードを備忘録として残します。

問題

A - Three-letter acronym

解説

https://img.atcoder.jp/arc072/editorial.pdf

解答例1

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

int main() {
  vector<string> str(3);
  for(int i = 0; i < 3; i++){
    cin >> str.at(i);
  }
  
  string result = "";
  
  for(string s: str){
    result += toupper(s.at(0));
  }
  cout << result << endl;
}

メモ

  • toupper():大文字に変換する

解答例2

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

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  
  // 文字コードの差を足し算して求める
  char dif = 'A'-'a';
  
  printf("%c%c%c\n", s1.at(0) + dif, s2.at(0) + dif, s3.at(0) + dif);
}

メモ

» HTML入門のまとめはこちらです。