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?

More than 1 year has passed since last update.

【APG4b AtCoder】ABC041 よわよわ学生のアルゴリズム4日目

Posted at

APG4b ABC041 よわよわ初心者解いてみた。

結果 -> 解けなかった(笑)

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

int main(){
  string s;
  int i;
  cin >> s >> i;
  i--;
  if(i>=0 && i<=s.size()){
    cout << s.at(i) << endl;
  }else{
    cout << "Out of range Error" << endl;
  }
}
//躓いたときのmain関数内↓
// string s;
//   int i;
//   char ans;
//   cin >> s;
//   cin >> i;
  
//   ans = s.at(i);
//   cout << ans << endl;
  • 最初躓いていたときは、RE errorが立て続けに出ていた。恐らくそれは、out of rangeエラーでi--していなかったのが原因だった!for文のときは、0から始まることを留意していたつもりだが、at()でもハマってしまったため、次回以降気を付けようと思う!
1
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
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?