【yukicoder】No.207 世界のなんとか
yukicoderさんの問題
参考書
難しさ(初心者目線)
・考え方*
・実装*
・面白さ*
コード
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <cmath> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #include <stdlib.h> #include <stdio.h> using namespace std; #define pb push_back #define mp make_pair #define ll long long #define PI acos(-1.0) #define ALL(A) (A).begin(), (A).end() #define vsort(v) sort(v.begin(),v.end()) #define FOR(I,A,B) for(int I = (A); I < (B); ++I) int main(){ ll int A, B; cin >> A >> B; string s; FOR(i, A, B+1){ if(i%3==0) cout << i << endl; else{ //stringにすると3を探すのが楽 s = to_string(i); if(s.find("3")!=-1) cout << i << endl; } } }
コメント
3の付く数字かどうか調べるのが厄介だけど数字をto_stringでstring型にしてからfindで3を探せば一発でわかる