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.

ABC063 ARC075 の問題を解いてみました

Posted at

A問題

愚直に実装しましょう。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//Created by karaju.

signed main(){
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  
  if(ans >= 10){ //10以上か判定する
    cout << "error" << endl;
  }
  else{
    cout << ans << endl;
  }
}

B問題

出現したアルファベットを記録しておいて、記録しておいた文字が出てきた場合noになります。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//Created by karaju.

signed main(){
  string s;
  cin >> s;
  
  vector<bool> ok(26, false);
  //出現したアルファベットを記録する配列
  
  for(int i = 0; i < s.size(); i++){
    if(ok[s[i] - 'a']){ // char - char で char を数字に直せる
      cout << "no" << endl;
      return 0;
    }
    else{
      ok[s[i] - 'a'] = true;
    }
  }
  cout << "yes" << endl;
}
別解
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//Created by karaju.

signed main(){
  string s;
  cin >> s;
  
  for(int i = 0; i < s.size(); i++){
    for(int j = i + 1; j < s.size(); j++){
      if(s[i] == s[j]){
        cout << "no" << endl;
        return 0;
      }
    }
  }
  cout << "yes" << endl;
}

C問題

まず、試験システムの欠陥を考慮せずに、すべての問題に正解した場合の点数を考えます。
その点数が10の倍数の場合は、試験システムの欠陥のために、10の倍数から抜け出したいです。

10の倍数から抜け出すには、10の倍数以外の数を引けばよいです。
10の倍数でない最も低い問題の配点を引けば答えが求められます。

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
//Created by karaju.

signed main(){
  int n;
  cin >> n;
  vector<int> s(n);
  int sum = 0;
  
  for(int i = 0; i < n; i++){
    cin >> s[i];
    sum += s[i]; //すべての問題の合計点を求める
  }
  
  int ans = 0;
  
  if(sum % 10 != 0){ //合計が十の倍数でないなら
    ans = sum;
  }
  else{
    sort(s.begin(), s.end()); //ソート
    for(int i = 0; i < n; i++){
      if(s[i] % 10 != 0){ //10の倍数でないなら
        ans = sum - s[i];
        break;
      }
    }
  }
  cout << ans << endl;
  
}

D問題

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?