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

解いた問題①

Last updated at Posted at 2020-05-13

問題1

A - Infinite Coins

# include <iostream>
# include <string>
using namespace std;
 
int main(){
  int N,A ;
  cin >> N >> A;
  if(N%500<=A) cout << "Yes" <<endl;
  else cout << "No" << endl;
}

問題2

A - Already 2018


# include <iostream>
# include <string>
using namespace std;

int main(){
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
}

問題3

B - i18n
std::to_string()で数値を文字列に変換できる。
string.length()で文字列の長さを取得できる。


# include <iostream>
# include <string>
using namespace std;

int main(){
  string s;
  cin >> s;
  int length = s.length();
  string ans = s[0] + std::to_string(length-2) + s[length-1];
  cout << ans << endl;
}

問題4

B - Shift only

# include <iostream>
# include <string>
using namespace std;

int main(){
  int N;
  int A[200];
  cin >> N;
  for(int i=0 ; i<N ; ++i) cin >> A[i];
  int res = 0;
  
  while(true){
    
    bool exist_odd =false;
    
    for(int i=0;i<N;++i){
      if(A[i]%2 != 0) exist_odd = true;
    }
    
    if(exist_odd) break;
    
    for(int i=0;i<N;++i) A[i] /= 2;
    
    ++res;
  }
  
  cout << res <<endl;
}

問題5

B - Maximum Difference

include <iostream>
using namespace std;
 
int main(){
  int N;
  long long int A[201];
  long long int max=0;
  long long int min=1000000000;
  cin >> N;
  for(int i=0; i<N ;++i){
    cin >> A[i];
    if(A[i]>max) max=A[i];
    if(A[i]<min) min=A[i];
  }
  cout << max-min <<endl;
}

問題6

B - OddString

# include<iostream>
# include<string>
using namespace std;

int main(){
  string s;
  cin >> s;
  string ans;
  for(int i=0;i<s.length();++i){
    if(i%2==0) ans+=s[i];
  }
  cout << ans << endl;
}

問題7

B - Coins



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?