みんなのプロコン 2018
A - yahoo
問題文通りに判定する.
#include <bits/stdc++.h> using namespace std; int main(void) { string s; cin >> s; if(s[0] == 'y' && s[1] == 'a' && s[2] == 'h' && s[3] == s[4]) { cout << "YES" << endl; } else { cout << "NO" << endl; } }
B - オークション
Xの桁数がK桁以下の場合, 答えは10^k円.
Xの桁数がK桁より大きい場合, K+1桁目を1増やし, 下K桁を0にする.
stoiやto_stringを使うとstringとintを往復出来て便利なことがわかった.
#include <bits/stdc++.h> using namespace std; int main(void) { string x; int k; cin >> x >> k; if(x.length() <= k) { string z; z += '1'; for(int i = 0; i < k; i++) { z += '0'; } cout << z << endl; return 0; } string ans; for(int i = 0; i < x.length() - k; i++) { ans += x[i]; } int anstoi = stoi(ans); anstoi++; ans = to_string(anstoi); for(int i = 0; i < k; i++) { ans += '0'; } cout << ans << endl; }
DPをまともに解いたことがないのでCに挑むのはまた今度にしたい(やらないフラグ).