output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> using namespace std; string str; string sub[3] = {"1", "14", "144"}; bool fign = false; void dfs(int i, int j) { if (j == str.length()) { fign = true; } else if (i == 2 && j != str.length()) { fign = false; } for (int i = 0; i < 3; i++) { string temp = str.substr(j, i + 1); ...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); ; long long int count = 0, i; string s; string a = "1", b = "14", c = "144"; cin >> s; for (i = 0; i < s.size(); i++) { string m, n, p; if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { c...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; const int oo = 1 << 30; int main() { int n; cin >> n; int k = n; string s = ""; while (k) { s += ('0' + (k % 10)); k /= 10; } reverse(s.begin(), s.end()); for (int i = 0; i + 2 < s.size(); i++) { string h = s.substr(i, 3); if (h == "144") { ...
### Prompt Your task is to create a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> char ch[15]; int main() { int i, j, len; while (gets(ch)) { len = strlen(ch); for (i = 0; i < len; i++) { if (ch[i] != '1' && ch[i] != '4') break; else if (!(ch[i] == '1' || (ch[i] == '4' && i > 0 && ch[i - 1] == '1') || (ch[i] == '4' && i > 1 &&...
### Prompt In cpp, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int flag = 0; if (s[0] != '1') cout << "NO" << endl; else { for (int i = 0; i < s.length(); i++) { if (s[i] != '1' && s[i] != '4') { flag++; cout << "NO" << endl; break; } else if (s.find...
### Prompt Create a solution in CPP for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; bool solve(int x) { if (x == 0) return true; if (x % 1000 == 144) { return solve(x / 1000); } else if (x % 100 == 14) { return solve(x / 100); } else if (x % 10 == 1) { return solve(x / 10); } return false; } int main() { int x; cin >> x; if (s...
### Prompt Your task is to create a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> int main() { long long int n, i, k, a; scanf("%lld", &n); k = n; for (i = 0; i < 10; i++) { a = k % 10; k = k / 10; if (k == 0 && a == 1) { printf("YES\n"); break; } else if (k == 0 && a != 1) { printf("NO\n"); break; } if (a == 1) { ...
### Prompt Please formulate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; long long int min(long long int a, long long int b) { return (a < b) ? a : b; } int main() { long long int n; int len = 0; cin >> n; while (n != 0) { if (n % 10 == 4) { if ((n % 100) / 10 == 4) { if ((n % 1000) / 100 == 1) n = n / 1000; ...
### Prompt Your task is to create a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, d; cin >> n; while (n > 0) { if (n % 1000 == 144) { n = n / 1000; } else if (n % 100 == 14) { n = n / 100; } else if (n % 10 == 1) { n = n / 10; } else { cout << "NO" << endl; return 0; } ...
### Prompt Your challenge is to write a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; bool isit(string s, int idx) { if (idx == s.length()) return true; if (s[idx] != '1') return false; else { bool b = isit(s, idx + 1); if (b) return true; else if (idx < int(s.length()) - 1) { if (s[idx + 1] == '4') { bool v = isit(s...
### Prompt Your task is to create a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; bool MN(const string &s, int i) { if (s[i] != '1') return false; if (i + 1 >= s.size()) return true; if (s[i + 1] == '4') { if (s[i + 2] == '4') return MN(s, i + 3); return MN(s, i + 2); } return MN(s, i + 1); } int main() { string s; cin >> s; s += ...
### Prompt Please create a solution in Cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; bool ismagical(string number) { for (long long int i = 0; i < number.length(); i++) if (number[i] != '1' && number[i] != '4') return false; if (number[0] != '1') return false; if (number.find("444") != number.npos) return false; return true; } int32_t main() { ...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; bool magic(string n) { for (int i = 0; i < (int)n.size(); i++) if (n[i] != '1' && n[i] != '4') return false; if (n[0] == '4') return false; if (n.find("444") != n.npos) return false; return true; } int main() { string n; cin >> n; if (magic(n)) { cout ...
### Prompt Generate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a...
#include <bits/stdc++.h> using namespace std; long long int n; int main() { cin >> n; while (n > 0) { if (n % 10 == 4) { n = n / 10; if (n % 10 == 1 && n > 0) { n = n / 10; } else if (n % 10 == 4 && n > 0) { n = n / 10; if (n % 10 == 1 && n > 0) { n = n / 10; ...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; long long inf = 100000000; template <class T> T bigmod(T b, T p, T m) { if (p == 1) return b; T res = bigmod(b, p / 2, m); res = (res * res) % m; if (p % 2 == 1) res = (res * b) % m; return res; } template <class T> T gcd(T x, T y) { if (y == 0) return x; retu...
### Prompt Generate a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a...
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; vector<string> v; void gen(string s) { if (s.size() > 9) return; v.push_back(s); gen(s + "1"); gen(s + "14"); gen(s + "144"); } int main() { gen(""); sort(v.begin(), v.end()); string s; cin >> s; if (binary_search(v.begin(), v.end(), ...
### Prompt Develop a solution in Cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int i, n, ans = 0, tmp = 0, j, t; string s; cin >> s; int k = s.length(); if (s[0] != '1') { cout << "NO" << endl; return 0; } for (i = 0; i < k; i++) { if (s[i] != '1' and s[i] != '4') { cout << "...
### Prompt Construct a Cpp code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string ans = "YES"; for (int i = 0; i < s.size();) { if (s[i] == '1' && s[i + 1] != '4') i += 1; else if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] != '4') i += 2; else if (s[i] == '1' && s[i + 1] == '4' && s...
### Prompt Your task is to create a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int test = 1; string aux = ""; for (int i = 0; (i < n.size()) && (test); i++) { aux = n[i]; if (aux == "1") { if (i + 1 < n.size()) { aux = aux + n[i + 1]; if (aux == "14") { if (i + 2 < n.si...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; string n; int main() { cin >> n; while (n.size()) { if (n.back() == '1') n.resize(n.size() - 1); else if (n.size() >= 2 && n.back() == '4' && n[n.size() - 2] == '1') n.resize(n.size() - 2); else if (n.size() >= 3 && n.back() == '4' && n[n.size() ...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; for (int i = 0; i < n.size(); i++) { if (n[i] != '1' && n[i] != '4') { cout << "NO" << endl; return 0; } } if (n[0] == '4' || n.find("444") != n.npos) { cout << "NO" << endl; return 0; } cout << "YES...
### Prompt Please provide a CPP coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; bool is(const string& s) { if (s.find("444") != string::npos) { return false; } for (int i = 0; i < s.size(); ++i) { if (s[i] != '1' && s[i] != '4') return false; } if (s[0] == '4') return false; } int main() { string s; cin >> s; if (is(s)) cout...
### Prompt Please create a solution in CPP to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> int main(int argc, char** argv) { std::string s, answer = "YES"; std::cin >> s; for (int i = 0; i < s.length();) { if (s.substr(i, 3) == "144") { i += 3; } else if (s.substr(i, 2) == "14") { i += 2; } else if (s[i] == '1') { i += 1; } else { answer ...
### Prompt Develop a solution in Cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i, c = 0; for (i = 0; i < s.size(); i++) { if (s[0] != '1') { c = 1; break; } else if (s[i] == '0' || s[i] == '2' || s[i] == '3' || s[i] == '5' || s[i] == '6' || s[i] == '7' || s[i] == '8' || s[...
### Prompt Please provide a Cpp coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main() { int i, n; string str; cin >> str; n = str.length(); for (i = 0; i < n; i++) { if (str[i] == '1') { if (str[i + 1] == '4' && i < n - 1) { if (str[i + 2] == '4' && i < n - 2) i += 2; else i++; } } ...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; string ulaz, jed = "1", dva = "14", tri = "144"; bool je[10]; int main() { cin >> ulaz; int l = ulaz.size(); for (int i = 0; i < l; i++) je[i] = false; for (int i = 0; i < l; i++) { if (je[i] == true) continue; if (i + 2 < l) { string nov; nov = ...
### Prompt Generate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool f = true; for (int i = 0; i < s.size(); i++) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i += 2; } else if (s[i] == '1' && s[i + 1] == '4') { i += 1; } else if (s[i] == '1') { } else { ...
### Prompt In CPP, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { long int n, flag = 0, i; cin >> n; while (n > 0) { if (n % 10 == 1) { n = n / 10; } else if (n % 100 == 14) { n = n / 100; } else if (n % 1000 == 144) { n = n / 1000; } else { flag++; break; } } if (fl...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { char arr[12]; int i, j, k, p, l; scanf("%s", &arr); l = strlen(arr); p = 0; for (i = 0; i < l;) { if (arr[i] - '0' == 1) { if (arr[i + 1] - '0' == 4) { if (arr[i + 2] - '0' == 4) { i = i + 3; } else { i ...
### Prompt Please formulate a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; bool flg = 0; for (long long i = 0; i < s.size(); i++) { cerr << "i" << " is " << i << '\n'; if (s[i] == '1') { if (i + 1 < s.size() and s[i + 1] == '4') ...
### Prompt Construct a CPP code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; int main() { char ch; int st = 0; while (cin >> ch) { switch (ch) { case '1': st = 1; break; case '4': if (st == 3 || st == 0) { cout << "NO" << endl; return 0; } else ++st; break; ...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; bool is_magic(const std::string &x) { int a = 2; for (size_t i = 0; i < x.size(); ++i) if (x[i] == '1') { a = 0; } else if (x[i] == '4') { if (++a > 2) { return false; } } else { return false; } return true; } int main()...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; void kick() { string s = ""; char c; int cn = 0; c = getchar(); while (c != ' ' && c != '\n') { s += c; if (c == '1') cn++; c = getchar(); } if (cn == s.length()) { cout << "YES" << endl; return; } bool fl = true; int tm = 0; for (i...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; void Solve(); int main() { Solve(); return 0; } void Solve() { string str; cin >> str; bool bol = true; for (int i = 0; i < str.length(); i++) { if (str[i] != '1' && str[i] != '4') { bol = false; break; } else if (str[0] != '1') { bol =...
### Prompt Generate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a...
#include <bits/stdc++.h> using namespace std; string s; int main() { int flag = 1, num = 0; cin >> s; if (s[0] != '1') flag = 0; for (int i = 0; s[i]; i++) { if (s[i] != '1' && s[i] != '4') { flag = 0; break; } else if (s[i] == '4') { num++; if (num > 2) { flag = 0; ...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; int main() { string ch; cin >> ch; while (ch[0] == '1') { if (ch.find("144") == 0) ch.erase(0, 3); else if (ch.find("14") == 0) { ch.erase(0, 2); } else if (ch.find("1") == 0) { ch.erase(0, 1); } } if (ch.size() == 0) cout << ...
### Prompt Generate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int kt = 1; if (s[0] == '4') kt = 0; else for (long i = 0; i < s.length(); i++) { if (s[i] != '1' && s[i] != '4') { kt = 0; break; } else if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') { ...
### Prompt Please formulate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string in; cin >> in; bool ok = 1; for (int i = 0; i < in.size(); i++) { if (in[i] != '1') { ok = 0; break; } int j = i + 1; int c = 0; while (j < in.size() && in[j] == '4') { j++; c++; } if (c > 2) { ...
### Prompt Your challenge is to write a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long t, n, m; int main() { scanf("%d", &n); int f = 0; int s = 0; while (n) { int x = n % 10; if (x == 4) s++; else if (x == 1) { if (s > 2) { f = 1; break; } s = 0; } else f =...
### Prompt In cpp, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n; int f = 1, i; while (n > 0) { x = n % 10; if (x == 1) { n = n / 10; } else if (x == 4) { n = n / 10; if (n % 10 == 1) { n = n / 10; } else if (n % 10 == 4) { if (n % 100 != 14) { ...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> int main() { int n, m, k, p = 1; scanf("%d", &n); m = n; while (m != 0) { if (m % 10 == 1) { m = m / 10; continue; } if (m % 100 == 14) { m = m / 100; continue; } if (m % 1000 == 144) { m = m / 1000; continue; } p = 0; ...
### Prompt In cpp, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> char a[300]; int main() { int len, i; while (scanf("%s", a) != EOF) { len = strlen(a); for (i = 0; i < len; i++) { if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4') { i += 2; continue; } if (a[i] == '1' && a[i + 1] == '4') { i += 1; ...
### Prompt Construct a cpp code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; bool magical(string s) { for (int i = 0; i < s.size(); i++) if (s[i] != '1' && s[i] != '4') return false; if (s[0] == '4') return false; if (s.find("444") != string::npos) return false; return true; } int main() { ios::sync_with_stdio(0); cin.tie(0); strin...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main() { long n; cin >> n; while (n != 0) { if (n % 10 == 1) { n /= 10; } else if (n % 100 == 14) { n /= 100; } else if (n % 1000 == 144) { n /= 1000; } else { cout << "NO"; return 0; } } cout << "YES"; retur...
### Prompt Generate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; while (true) { if (n % 1000 == 144) n /= 1000; else if (n % 100 == 14) n /= 100; else if (n % 10 == 1) n /= 10; else { break; } ...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); string s; cin >> s; if (s[0] != '1') { cout << "NO"; return 0; } int i = 0; while (i < s.size()) { if (s[i] != '1' && s[i] != '4') { cout << "NO"; return...
### Prompt Your task is to create a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; getline(cin, s); int n = s.length(); bool ok = true; int num4s = 0; for (int i = n - 1; i >= 0; i--) { int k = s[i] - '0'; if (k == 1) { if (num4s <= 2) { ...
### Prompt Please create a solution in cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int x = 0; while (s[x] == '1' && x <= s.size()) { if (s.substr(x, 3) == "144") x += 3; else if (s.substr(x, 2) == "14") x += 2; else x++; } if (x == s.size()) cout << "YES" << endl; else co...
### Prompt In cpp, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; bool flag = true; long long x; long long n = s.length(); for (long long i = 0; i < n;) { if (s[i] == '1') { i++; if (s[i] == '4') { i++; ...
### Prompt Please provide a Cpp coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long long ULL; const double pi = acos(-1.0); const double eps = 1e-11; const int MAXI = 0x7fffffff; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; const char dz[] = "SENW"; struct debugger { template <typename T> d...
### Prompt Your task is to create a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n > 0) { if (n % 1000 == 144) { n /= 1000; } else if (n % 100 == 14) { n /= 100; } else if (n % 10 == 1) { n /= 10; } else { cout << "NO" << endl; return 0; } } cout << "YES" <<...
### Prompt Your challenge is to write a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> int main() { char s[20]; scanf("%s", s); int i, j, f = 0, c = 0; if (s[0] != '1') { f = 1; } else { for (i = 1; s[i]; i++) { if (s[i] != '1' && s[i] != '4') { f = 1; break; } else if (s[i] == '4') { for (j = i; s[j]; j++) { if (s[j...
### Prompt Please provide a CPP coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; bool isMagic(int n) { while (n > 0) { while (n % 1000 == 144) { n /= 1000; } while (n % 100 == 14) { n /= 100; } while (n % 10 == 1) { n /= 10; } if (n == 0) { return true; } if (n % 100 != 14 and n % 1000 != 144...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main() { int len; string str, n1, n2, n3; cin >> str; len = str.size(); str += "11111"; bool chk = true; for (int i = 0; i < len; i++) { n1 = str[i]; n1 += str[i + 1]; n1 += str[i + 2]; n2 = str[i]; n2 += str[i + 1]; n3 = str[i]; ...
### Prompt Please formulate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; string input; regex rex1("^((1)*(14)*(144)*)*$"); void inputData() { cin >> input; if (regex_match(input, rex1)) { cout << "YES"; } else { cout << "NO"; } } int main(int argc, char** argv) { inputData(); }
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> template <typename T> inline T gcd(T a, T b) { T c; while (b) { c = b; b = a % b; a = c; } return a; } template <typename T> T lcm(T a, T b) { return b * (a / gcd(a, b)); } template <typename T> inline T pow2(T base, T n) { T ansp = 1; while (n) { if (n & 1) ansp *...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main() { string palavra; cin >> palavra; int flag = 1; for (int i = 0; i < palavra.size(); ++i) { if (palavra[i] == '1') { if (palavra[i + 1] == '4' && palavra[i + 2] == '4') { i += 2; continue; } else if (palavra[i + 1] == '4') {...
### Prompt Your task is to create a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; const long long int INF = 1e18; const long long int inf = 1e9 + 5; const long long int MOD = 1e9 + 7; long long int gcd(long long int a, long long int b) { return !a ? b : gcd(b % a, a); } long long int lcm(long long int a, long long int b) { return a / gcd(a, b) * b; }...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; bool is_magical(string number) { for (int i = 0; i < (int)number.size(); i++) if (number[i] != '1' && number[i] != '4') return false; if (number[0] == '4') return false; if (number.find("444") != number.npos) return false; return true; } int main() { string nu...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); string s; cin >> s; bool ok = true; for (int i = 0; i < s.size(); i++) { if (i + 1 < s.size() && i + 2 < s.size() && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') i += 2; ...
### Prompt Please create a solution in cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> int main() { int a, b, c; char s[100]; gets(s); a = 0, b = 0, c = 0; while (s[a] != '\0') { if (s[a] == '1') b = 1; else if (b == 0) { c = 1; break; } else if (b <= 2 && s[a] == '4') b++; else if (s[a] != 1) c = 1; else b = 1; ...
### Prompt Create a solution in cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; int main() { int one = 0, four = 0; string s; cin >> s; if (s[0] != '1') { printf("NO\n"); return 0; } for (int i = 0; s[i]; i++) { if (s[i] != '1' && s[i] != '4') { printf("NO\n"); return 0; } } for (int i = 1; s[i]; i++) { i...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; template <typename T> bool prime(T n) { if (n <= 1) return false; if (n <= 3) return true; if (n & 1 ^ 1 || n % 3 == 0) return false; for (T i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } int main() { ios_base::sy...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string str; cin >> str; int f = 0; if (str[0] != '1') { cout << "NO" << endl; return 0; } for (int i = 1; i < str.length(); ++i) { if (str[i] == '4') { ++f; if (f > 2) { cout << "NO" << endl; return 0; }...
### Prompt Please formulate a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { int i, len, flag = 0; char a[9]; gets(a); len = strlen(a); for (i = 0; i < len; i++) { if (a[i] == '1' && a[i + 1] == '4' && a[i + 2] == '4') i = i + 2; else if (a[i] == '1' && a[i + 1] == '4') i = i + 1; else if (a[i] == '1') ...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { int n; while (scanf("%d", &n) != EOF) { bool flag = 0; while (n && flag == 0) { if (n % 10 == 1) n /= 10; else if (n % 10 == 4) { int tmp = n / 10; if (tmp % 10 == 1) n /= 100; else if (tmp % 10 ...
### Prompt Please provide a cpp coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main() { string g; cin >> g; int n = g.size(); for (int i = 0; i < n; i++) { if (g[i] != '1' and g[i] != '4') { cout << "NO" << endl; return 0; } } if (g[0] == '4') { cout << "NO" << endl; return 0; } for (int i = 1; i < n; i+...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; int main() { int i, tam, flag = 0; char magic[20]; cin >> magic; tam = strlen(magic); if (magic[0] != '1') flag = 1; for (i = 0; i < tam; i++) { if (magic[i] == '4' && magic[i + 1] == '4' && magic[i + 2] == '4') flag = 1; if (magic[i] != '4' && magic[i] ...
### Prompt Your task is to create a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determ...
#include <bits/stdc++.h> using namespace std; int main() { int n, m, k, c, ans = 0; string s; cin >> s; bool sol = 1; for (int i = 0; i < s.length(); i++) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i += 2; continue; } if (s[i] == '1' || (s[i] == '4' && s[i - 1] == '1'))...
### Prompt Please create a solution in Cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); string n; cin >> n; int i = 0; while (i < n.size()) { if (n[i] == '1') { i++; continue; } else if (n[i] == '4') { if (i > 0 && n[i - 1] == '1') { i++; continue; } ...
### Prompt In CPP, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { int n, flag = 1; scanf("%d", &n); while (n) { if (n % 10 == 4) { n /= 10; if (n % 10 == 4) { n /= 10; if (n % 10 != 1) flag = 0; } else if (n % 10 == 1) n /= 10; else flag = 0; } else if (n %...
### Prompt In Cpp, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main(void) { char sav[200]; scanf("%s", sav); int flag = 0; int len = strlen(sav); for (int i = 0; i < len; i++) { if (sav[i] == '1') continue; else if (sav[i] == '4') { if (i - 1 >= 0 && sav[i - 1] == '1') continue; else if (...
### Prompt Please formulate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { char c[20]; cin >> c; int p = 0, n = strlen(c); bool es = true; while (p < n) { if (c[p] == '1' && c[p + 1] == '4' && c[p + 2] == '4') { p += 3; } else if (c[p] == '1' && c[p + 1] == '4') { p += 2; }...
### Prompt Construct a Cpp code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; int main() { string str; int n, i, k = 0; cin >> str; for (i = 0; i < str.size(); ++i) { if (str[0] != '1') { break; } if (str[i] != '1' && str[i] != '4') { break; } if (str[i] == '1') { k = 1; } if (str[i] == '4') { ...
### Prompt Create a solution in CPP for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(); int f = 1; for (int i = 0; i < n; i++) { if (s[i] == '1') { if (i + 1 < n) { if (s[i + 1] == '4') { if (i + 2 < n) { if (s[i + 2] == '4') i += 2; e...
### Prompt Construct a Cpp code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; inline void print(int pt) { printf("%d\n", pt); } inline void print(long long pt) { printf("%I64d\n", pt); } inline void print(double pt) { printf("%f\n", pt); } inline void print(char pt[]) { printf("%s\n", pt); } inline void scan(int &pt) { scanf("%d", &pt); } inline void...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string str; int flag = 1; cin >> str; int len = str.size(); str[len] = '1'; str[len + 1] = '1'; for (int i = 0; i < str.size();) { string temp = ""; if (str[i] == '1') { temp = str[i + 1]; if (temp == "4") { temp += str...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; char g[20]; int main() { scanf("%s", g); int len = strlen(g); int flag = 0; for (int i = 0; i < len;) { if (g[i] == '1' && g[i + 1] == '4' && g[i + 2] == '4') { i += 3; continue; } if (g[i] == '1' && g[i + 1] == '4') { i += 2; con...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main() { string n; cin >> n; int i = 0; while (i < n.size()) { if (n[i] == '1') { if (i + 1 < n.size() and n[i + 1] == '4') { if (i + 2 < n.size() and n[i + 2] == '4') { i += 3; continue; } else { i += 2; ...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; int m = 0; while (n > 0) { m++; if ((n - 144) % 1000 == 0) { n -= 144; n /= 1000; } else if ((n - 14) % 100 == 0) { n -= 14; n /= 100; } else if ((n - 1) % 10 == 0) { n -= 1; n /...
### Prompt In Cpp, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i, c = 0; for (i = 0; s[i] != '\0';) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i = i + 3; } else if (s[i] == '1' && s[i + 1] == '4') { i = i + 2; } else if (s[i] == '1') { i = i + 1;...
### Prompt Please create a solution in cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; const int inf = 0x7fffffff; int main() { int n, a[10]; while (cin >> n) { memset(a, 0, sizeof(a)); int i = 0; while (n) { a[i] = n % 10; n /= 10; i++; } i -= 1; int flag = 0; reverse(a, a + i + 1); for (int j = 0; j <= i...
### Prompt Please formulate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { int num; int test = 0; cin >> num; bool mg = true; while (num != 0) { int dic = num % 10; num = num / 10; if (dic == 1) { test = 0; } else if (dic == 4 && test < 2) { test += 1; } else { mg = false; } } if...
### Prompt In CPP, your task is to solve the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it i...
#include <bits/stdc++.h> using namespace std; int main() { string ip; int f = 0, i = 0, j; cin >> ip; while (i != ip.size()) { if (ip[i] == '1') { i++; if (ip[i] == '4' && i < ip.size()) { i++; if (ip[i] == '4' && i < ip.size()) i++; } f = 1; } else { f = 0;...
### Prompt Please create a solution in cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; bool flag = true; while (n > 0) { if (n % 1000 == 144) n /= 1000; else if (n % 100 == 14) n /= 100; else if (n % 10 == 1) n /= 10; else { cout << "NO" << "\n"; flag = false; ...
### Prompt Your challenge is to write a Cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; string s; bool fun(int i) { if (i >= s.size()) return 1; if (s[i] == '1') { if (s[i + 1] == '4') { if (s[i + 2] == '4') return fun(i + 3); else return fun(i + 2); } else return fun(i + 1); } else return 0; } int main() { ...
### Prompt Please create a solution in Cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int i = 0; int flag1 = 0, flag2 = 0, flag3 = 0; while (i < s.length()) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { flag1 = 1; i += 3; } else if (s[i] == '1' && s[i + 1] == '4') { flag2 = 1; ...
### Prompt Please formulate a CPP solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string n; int i, j, flag = 0, ar[20]; cin >> n; for (i = 0; i < n.size(); ++i) { ar[i] = n[i] - '0'; } for (i = 0; i < n.size(); ++i) { if (ar[i] != 1 && ar[i] != 4) flag = 1; if (ar[i] == 1) ; if (ar[i] == 4) { if (i == ...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; long long fastpow(long long a, long long b, long long m = (long long)(1e9 + 7)) { long long res = 1; a %= m; while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res; } long long mulmod(long long a, long ...
### Prompt Develop a solution in CPP to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { if (s[i + 1] == '4') { if (s[i + 2] == '4') { i = i + 2; continue; } else i++; continue; } else con...
### Prompt Please provide a cpp coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int cnt; int main() { string s; cin >> s; if (s[0] == '4') { cout << "NO"; return 0; } else { for (int i = 0; i < s.size(); i++) { if (s[i] != '1' && s[i] != '4') { cout << "NO"; return 0; } else { if (s[i] == '4') { ...
### Prompt Construct a Cpp code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int count = 0; int t = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '1' || s[i] == '4') { t = 0; } else { t = 1; cout << "NO"; break; } } if (t == 0) { int h = 0; int j = 0; ...
### Prompt Construct a CPP code solution to the problem outlined: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it...
#include <bits/stdc++.h> using namespace std; int main() { string str; getline(cin, str); bool possible = true; for (int i = 0; i < str.length(); i++) { if (str.substr(i, 3) == "144") i += 2; else if (str.substr(i, 2) == "14") i++; else if (str.substr(i, 1) == "1") continue; el...
### Prompt Create a solution in Cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; template <typename T, typename U> std::pair<T, U> operator+(const std::pair<T, U>& l, const std::pair<T, U>& r) { return {l.first + r.first, l.second + r.second}; } typedef void (*callback_function)(void); const long long ZERO = 0LL; const long long INF64 = 1e18; const lo...
### Prompt Create a solution in cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...
#include <bits/stdc++.h> using namespace std; string ismagic(const string &s) { if (s.length() == 0) { return "YES"; } long long i = 0; while (i < s.length()) { if (s.substr(i, 3) == "144") { i += 3; } else if (s.substr(i, 2) == "14") { i += 2; } else if (s.substr(i, 1) == "1") { ...
### Prompt Please provide a CPP coded solution to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; int main(void) { long long int a, n; cin >> n; a = n; while (true) { if (n % 1000 == 144) { n = n / 1000; continue; } else if (n % 100 == 14) { n = n / 100; continue; } else if (n % 10 == 1) { n = n / 10; continue; ...
### Prompt Develop a solution in cpp to the problem described below: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int INF = INT_MAX; const int NINF = INT_MIN; string s; void Solve() { cin >> s; for (int i = 0; i <= s.length() - 1; i++) { if (i + 2 < s.length() && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i += 2; cont...
### Prompt Please create a solution in cpp to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool isMagic = true; int i = 0; for (i = 0; i < s.size(); i++) { if (s[0] == '4') { isMagic = false; break; } else if (s[i] == '1') continue; else if (s[i] == '4') { int consec_four = 1; wh...
### Prompt Your challenge is to write a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. De...
#include <bits/stdc++.h> using namespace std; string solve(string s) { int one, four; one = four = 0; for (int i = 0; i < s.size(); ++i) { if (s[i] == '1') { ++one; } else if (s[i] == '4') { ++four; } else { return "NO"; } } if (one < 1) { return "NO"; } if (s[0] == '...
### Prompt Please formulate a cpp solution to the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if...
#include <bits/stdc++.h> using namespace std; int main() { int n, a[10], k = 0, t = 1000000000; scanf("%d", &n); if (n == 1000000000) printf("NO"); else { for (; t >= 10; t /= 10) { if (k != 0) { a[k] = ((n % t) - (n % (t / 10))) / (t / 10); k++; } else { if (((n % t)...
### Prompt Create a solution in cpp for the following problem: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is...