output
stringlengths
52
181k
instruction
stringlengths
296
182k
#include <bits/stdc++.h> int main() { int f = 0; long long int n; scanf("%lld", &n); for (; n != 0;) { if (n % 10 == 1) n /= 10; else if (n % 100 == 14) n /= 100; else if (n % 1000 == 144) n /= 1000; else { f = 1; break; } } f == 0 ? printf("YES") : printf("...
### 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> int main() { int n, x, y, z, f = 0; scanf("%d", &n); while (n > 0) { x = n % 10; n = n / 10; if (x == 4 && n > 0) { y = n % 10; n = n / 10; if (y == 1) { if (!((y * 10 + x) == 14)) { f = 1; break; } } else if (y == 4 ...
### 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 comment(linker, "/STACK:256000000") using namespace std; string s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> s; if (s[0] != '1') { cout << "NO"; return 0; } int cur = 0; for (int i = 1; i < (int)s.size(); i++) { if (s[i] != '1' && s[i] !...
### 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 x, y; cin >> x; while (x != 0) { y = x % 10; if (y == 4) { x /= 10; y = x % 10; if (y == 1) continue; else if (y == 4) { x /= 10; y = x % 10; if (y != 1) { cout << "NO"; ...
### 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 s[11]; int i, l, flag = 0; scanf("%s", s); l = strlen(s); for (i = 0; i < l;) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') i += 3; else if (s[i] == '1' && s[i + 1] == '4') i += 2; else if (s[i] == '1') i+...
### 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> #pragma GCC optimize("O3") #pragma loop_opt(on) using namespace std; template <class T> using vec = vector<T>; template <class T> using stack = stack<T, vec<T> >; template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vec<T>, greater<T> >; int...
### 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, f = 0, r; cin >> n; while (n) { if (n % 10 == 1) n /= 10; else if (n % 100 == 14) n /= 100; else if (n % 1000 == 144) n /= 1000; else { f = 1; break; } } if (f == 0) cout << "YES"; el...
### 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; bool magic(long long int n) { while (n) { if (n % 10 == 1) { n = (n - (n % 10)) / 10; } else { if (n % 100 == 14) n = (n - (n % 100)) / 100; else { if (n % 1000 == 144) n = (n - (n % 1000)) / 1000; else ...
### 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() { int 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"; return 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() { long long n; cin >> n; while (n) { if (n % 10 != 1 && n % 100 != 14 && n % 1000 != 144) { cout << "NO"; return 0; } n /= 10; } cout << "YES"; return 0; }
### 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 s; int f = 0, o = 0; cin >> s; for (int i = s.size() - 1; i >= 0; i--) { if (f > 2) { cout << "NO\n"; return 0; } if (s[i] == '4') f++; else if (s[i] == '1') f = 0; else { cout << "NO\n"; re...
### 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 sol(int i) { if (i >= s.size()) return 1; int c1 = 0, c2 = 0, c3 = 0; if (s[i] == '1') c1 = sol(i + 1); if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') c2 = sol(i + 3); if (s[i] == '1' && s[i + 1] == '4') c3 = sol(i + 2); return max(c1, max...
### 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 s; std::cin >> s; int n = s.length(); int i{}; while (i < n) { if (s[i] == '1') { if (i < n - 1 && s[i + 1] == '4') { if (i < n - 2 && s[i + 2] == '4') { i += 3; continue; } i += 2; ...
### 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; long long len = s.length(), count = 0, flag = 1; while (count < len) { if (count < len - 2 && s[count] == '1' && s[count + 1] == '4' && s[count + 2] == '4') { count += 3; } else { if (count < len - 1 && s[...
### 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 x; cin >> x; for (int i = 0; i < x.size(); i++) { if (x[i] == '1' && x[i + 1] == '4' && x[i + 2] == '4') { i += 2; continue; } else if (x[i] == '1' && x[i + 1] == '4') { i += 1; continue; } else if (x[i] == '1') ...
### 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 flag = 1; long long int n, i, x; cin >> x; n = x; for (i = 0; n != 0; i++) { if (n % 10 == 4 && n / 10 == 0) { flag = 0; cout << "NO" << endl; return 0; } else if (n % 10 == 4 || n % 10 == 1) flag = 1; else { ...
### 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> const long long int MOD = 1e9 + 7; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; int dx4[] = {0, 0, 1, -1}; int dy4[] = {1, -1, 0, 0}; using namespace std; void vok() { ios_base::sync_with_stdio(false); cout.tie(NULL); cin.tie(NULL); } string func(strin...
### 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, state(0); cin >> n; bool magic(true); while (n != 0) { int d = n % 10; n /= 10; if (d == 1) { state = 0; } else if (d == 4 && state < 2) { state = state + 1; } else { magic = false; } } if (state != 0...
### 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_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; int flag = 0; for (int i = 0; i < s.length();) { if (s[i] == '1') { i++; if (s[i] == '4') { i++; if (s[i] == '4') { i++; } else { ...
### 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(false); cin.tie(NULL); string x; cin >> x; int flag = 0; for (int i = 0; i < x.length(); i++) { if (i + 2 < x.length() && x[i] == '1' && x[i + 1] == '4' && x[i + 2] == '4') { flag++; i = i + 2; }...
### 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() { char num[101]; int len, i; scanf("%s", num); len = strlen(num); for (i = 0; i < len; i++) { if (num[i] != '1' && num[i] != '4') break; else if (num[i] == '4') { if (!((i - 1 >= 0 && num[i - 1] == '1') || (i - 2 >= 0 && num[i - 2] == '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> int main() { char s[11]; scanf("%s", s); char y = '-', x = '-'; int i; for (i = 0; i < strlen(s); i++) { if (s[i] == '1') { x = '1'; continue; } if (s[i] == '4') { if (x == '1') { x = '4'; y = '1'; continue; } if (x == ...
### 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 m, c = 0; string s; cin >> s; m = s.length(); for (int i = 0; i < m; i++) { if (s[i] != '1' && s[i] != '4') { c = 1; break; } } if (c == 1) { cout << "NO"; } else if (c == 0) { if (s[0] == '4') { c = 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; const long long int MAX = 1e5 + 5; const long long int INF = 2e18; int main() { long int n; cin >> n; int arr[10], i, j = 0, cnt4 = 1; while (n) { arr[j] = n % 10; n = n / 10; j++; } if (j > 1) { for (i = j - 1; i >= 0; i--) { if (arr[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() { string s; bool flag = true; cin >> s; for (int i = 0; i < s.length();) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i += 3; } else if (s[i] == '1' && s[i + 1] == '4') { i += 2; } else if (s[i] == '1') { 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; long long int arr[100009]; int main() { int n, m, s, p, q, ans = 0; scanf("%d", &n); m = n; int dig, flag = 0; while (m != 0) { dig = m % 10; if (dig != 1 && dig != 4) { cout << "NO"; return 0; } if (dig == 4) flag++; if (dig == 1) ...
### 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 magic(string s) { for (int i = 0; s[i]; i++) { if (s[i] != '1' && s[i] != '4') return false; } if (s[0] == '4') return false; if (s.find("444") != s.npos) return false; return true; } int main() { string number; cin >> number; bool ans = magic(numbe...
### 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(void) { string s; cin >> s; int flag = 0; int i; for (i = 0; i < s.size(); i++) { if (s[i] != '1' && s[i] != '4') { flag = 1; } } if (s.find("444") != s.npos) { flag = 1; } if (s[0] == '4') { flag = 1; } if (flag == 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; int main() { string s; cin >> s; bool ans = true; for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { if (s[i + 1] == '4' && s[i + 2] == '4') i += 2; else if (s[i + 1] == '4') i++; } else { ans = false; break; ...
### 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() { long long n; int flag = 1; 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 { flag = 0; break; } } if (flag == 0) co...
### 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; vector<int> element, element1; list<int> datal; stack<int> datas; queue<int> dataq; map<string, int> datam; set<int> datase; vector<int>::iterator itv; list<int>::iterator itl; map<string, int>::iterator itm; set<int>::iterator itse; int main() { int i, len; string text...
### 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() { ios_base::sync_with_stdio(0); cin.tie(0); long long i; string str; bool flag = true; cin >> str; for (i = 0; i < str.length();) { if (str[i] == '1' && str[i + 1] == '4' && str[i + 2] == '4') i += 3; else if (str[i] == '1' && str[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() { string s; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '1') continue; if (s[i] == '4' && s[i - 1] == '1') continue; if (s[i] == '4' && i > 1 && s[i - 1] == '4' && s[i - 2] == '1') continue; return cout << "NO", 0; } cout ...
### 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 i_max(int arr[], int n) { int MAX = arr[0]; int i1 = 0, i2 = 0; for (int i = 0; i < n; i++) { if (arr[i] > MAX) { MAX = arr[i]; i1 = i; i2 = i; } else if (arr[i] == MAX) { i2 = i; } } return max(i1, i2); } int i_min(long lon...
### 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 s; int flag = 1; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { if (i == s.length() - 1) break; if (s[i + 1] == '4') { if (i == s.length() - 2) break; if (s[i + 2] == '4') { 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() { char a[11]; scanf("%s", a); int n = strlen(a); int f = 0; for (int i = 0; i < n;) { if (a[i] == '1') { if (i + 1 < n and a[i + 1] == '4') { if (i + 2 < n and a[i + 2] == '4') { i += 3; } else { i += 2; ...
### 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 int N = 100000 + 10; vector<int> ans; int main() { string s; cin >> s; int cnt1 = 0, cnt4 = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { cnt1++; cnt4 = 0; } else if (s[i] == '4' && cnt1) { cnt4++; if (cnt4 > 2) {...
### 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 = 0, flag = 0; int n = s.size(); if (s.size() == 1 && s[0] == '1') cout << "YES"; else if (s.size() == 1 && s[0] != '1') cout << "NO"; else { while (i < n) { if (s[i] != '1' && s[i] != '4') { fla...
### 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 num; cin >> num; int len = num.size(); for (int i = 0; i < len;) { if ((num[i] != '1') && (num[i] != '4')) { cout << "NO" << endl; return 0; } else if (num[i] == '1' && num[i + 1] != '4') { i++; } else if (num[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 n; cin >> n; string s = "YES"; while (n > 0) { if (n % 10 == 1) n /= 10; else if (n % 100 == 14) n /= 100; else if (n % 1000 == 144) n /= 1000; else { s = "NO"; break; } } cout << s << endl; re...
### 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; void solve(); int main() { solve(); return 0; } void solve() { string s; int i; cin >> s; if (s[0] == '4') { cout << "NO"; } else if (s.find("444") != s.npos) { cout << "NO"; } else { for (i = 0; i < s.length(); i++) { if (s[i] != '1' && s[...
### 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 str[100000]; scanf("%s", str); int count = 1; if (str[0] == '1') { for (int i = 1; i < strlen(str); i++) { if (str[i] == '4' && str[i - 1] == '1') { count = 1; } else if (str[i] == '4' && str[i - 1] == '4' && str[i - 2] == '1') { count =...
### 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, x = s.length(); while (i < x) { if (s.substr(i, 3) == "144") { i += 3; } else if (s.substr(i, 2) == "14") { i += 2; } else if (s[i] == '1') { i++; } else { cout << "NO" << endl; ...
### 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 str; cin >> str; int n = str.length(); for (int i = 0; i < n; i++) { if (i + 2 < n && str.substr(i, 3) == "144") { i += 2; } else if (i + 1 < n && str.substr(i, 2) == "14") { i += 1; } else if (str[i] == '1') { conti...
### 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; bool solve(string s, int p) { if (p == (int)s.length()) { return true; } for (int i = p; i < (int)s.length(); i++) { string a = s.substr(p, i - p + 1); if (a == "1" || a == "14" || a == "144") { if (solve(s, i + 1)) { return true; } ...
### 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 l, i, c = 0; l = s.size(); for (i = 0; i < l; i++) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { c += 3; } else if (s[i] == '1' && s[i + 1] == '4') { c += 2; } else if (s[i] == '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() { int n; cin >> n; string s = to_string(n); int ans = 0, k = 0; if (s[0] == '1') { for (int i = 0; i < s.length(); i++) { if (s[i] == '1') { if (ans > 2) { k++; break; } else ans = 0; } else ...
### 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; void _print(long long t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } template <class T, class V> void _print(pair<T, V> p); template <class T> void _print(vector<T> v); template <class T> v...
### 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 number; cin >> number; while (number > 0) { if (number % 10 == 1) number /= 10; else if (number % 100 == 14) number /= 100; else if (number % 1000 == 144) number /= 1000; else { cout << "NO"; return ...
### 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 = 0; string nr; cin >> nr; while (i < nr.length()) { if (nr[i] == '1' && nr[i + 1] == '4' && nr[i + 2] == '4') { i += 3; continue; } if (nr[i] == '1' && nr[i + 1] == '4') { i += 2; continue; } if (nr[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; int main() { string s; cin >> s; int m = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i += 2; m += 3; } else if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] != '4') { i++; m += 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() { int f = 0; string s; cin >> s; for (int i = 0; i < s.size();) { if (s[i] == '1') { i++; if (s[i] == '4') { i++; if (s[i] == '4') { i++; } } } else { f = 1; break; } } if (f ...
### 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 mod = 1e9 + 7; using namespace std; bool isp(long long x) { for (long long i = 2; i * i <= x; ++i) if (x % i == 0) return false; return true; } void pog() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; } bool sortinrev(const pair<long long, long long> &a, ...
### 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; string t; for (int i = 0; i < n.size(); i++) { if (n[i] == '1' && n[i + 1] == '4' && n[i + 2] == '4' && i + 1 < n.size() && i + 2 < n.size()) { t.append(1, n[i]); t.append(1, n[i + 1]); t.append(1, n[i +...
### 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 unsigned long long maxn = 2e6 + 10; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string v; cin >> v; for (long i = 0; i < v.size(); i++) { if (v[i] != '1' && v[i] != '4') { cout << "NO" << endl; return 0; } } if (...
### 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() { char s[100]; int i, kt = 0; scanf("%s", s); int l = strlen(s); for (i = 0; i < l; i++) if (s[i] == '1') { kt = 1; if (s[i + 1] == '4') { if (s[i + 2] == '4') { i = i + 2; } else i = i + 1; } else i = i; ...
### 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 n; cin >> n; int len = n.length(); int i, flag = 0; for (i = 0; i < len; i++) { if (n[i] == '1' && n[i + 1] == '4' && n[i + 2] == '4') { flag = 0; i += 2; } else if (n[i] == '1' && n[i + 1] == '4') { flag = 0; 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() { string s; cin >> s; for (int i = 0; i < s.length(); i++) { if ((s[i] != '1' && s[i] != '4') || (s[0] == '4')) { cout << "NO" << endl; return 0; } if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') { cout << "NO" << endl; ...
### 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 s; cin >> s; int n = s.length(); int flag = 1; for (int i = 0; i < n; 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++; else if (s[i] == '1') co...
### 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 MAXN = 1e5 + 256; const int N = 1256; const int INF = int(1e9); char c; bool ans = 1; int four, num; string str[] = {"NO", "YES"}; int main() { ios_base ::sync_with_stdio(false); cin.tie(0); while (cin >> c) { if ((c != '4' && c != '1') || (four > 2) || ...
### 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 arr[1005][1005], r[1005], c[1005]; int main() { long long int x, a, b, c; cin >> x; while (x != 0) { a = x % 1000; b = x % 100; c = x % 10; if (a == 144) x /= 1000; else if (b == 14) x /= 100; else if (c == 1) x /= 10; ...
### 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 sortBySecond(pair<int, int> a, pair<int, int> b) { return a.second < b.second; } void Code() { string str; cin >> str; int four = 0; for (int i = 0; i < str.size(); i++) { if ((str[i] != '1' && str[i] != '4') || four >= 3) { cout << "NO"; retu...
### 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 s, ans; cin >> s; int n = strlen(&s[0]); string tem; for (int i = 0; i < n; 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] == ...
### 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() { char str[15]; int cnt = 0; cin >> str; for (int i = 0; i <= strlen(str) - 1; i++) { if (str[i] == '1' && str[i + 1] != '4') cnt++; else if (str[i] == '1' && str[i + 1] == '4' && str[i + 2] != '4') cnt += 2; else if (str[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; int main() { ios::sync_with_stdio(0); string s; cin >> s; int i = 0; bool ans = true; while (i < s.length() && ans == true) { if (i + 2 < s.length() && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') i += 3; else if (i + 1 < s.length() && s[i] =...
### 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; for (int i = 0; i < (int)s.size(); i++) { string t1 = s.substr(i, 1); string t2 = s.substr(i, 2); string t3 = s.substr(i, 3); if (t3 == "144") s.erase(i, 3), i--; else if (t2 == "14") s.erase(i, 2), i--;...
### 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 flag = 1; if (s[0] != '1') { cout << "NO"; return 0; } for (int i = 0; s[i] != '\0'; i++) { if (s[i] == '1') { continue; } else if (s[i] == '4' && s[i + 1] == '4') { if (s[i - 1] != '1') fl...
### 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 = 0; if (s[0] != '1') { f = 1; } for (int i = 0; i < s.size(); i++) { if (s[i] != '1' && s[i] != '4') { f = 1; } } if (s.find("444") != -1) { f = 1; } if (f == 1) cout << "NO"; else ...
### 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; string solve() { string s; cin >> s; int n = s.length(), count = 0; if (s[0] == '4') return "NO"; for (int i = 0; i < n; i++) { if (s[i] != '1' and s[i] != '4') return "NO"; if (s[i] == '4') count++; else count = 0; if (count > 2) retur...
### 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; long long lent, flag = 0; cin >> s; lent = s.length(); for (long long i = 0; i < lent; i++) { if (s[i] == '1') continue; else if (s[i] == '4') { if (i == 0) { flag = 1; break; } else if (s[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() { string s; cin >> s; int len = s.length(); bool ismagic = true; for (int i = 0; i < len;) { if (s[i] == '1' & s[i + 1] == '4' && s[i + 2] == '4') { i += 3; } else if (s[i] == '1' && s[i + 1] == '4') { i += 2; } else if (s[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; void solve() { string s; cin >> s; regex r("((1)|(14)|(144))*"); cout << (regex_match(s, r) ? "YES\n" : "NO\n"); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long T; T = 1; for (int t = 0; t < T; t++) { solve()...
### 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() { int flag, l, i; char str[100005]; while (cin >> str) { flag = 0; l = strlen(str); for (i = 0; i < l;) { if (str[i] == '1' && str[i + 1] == '4' && str[i + 2] == '4') i += 3; else if (str[i] == '1' && str[i + 1] == '4') ...
### 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 long int num, c1 = 0, c2 = 0, flag = 0; cin >> num; stringstream ss; ss << num; string n; ss >> n; for (int i = 0; i < n.size(); i++) { if (n[i] == '1') { if (n[i + 1] == '4') { i++; if (n[i + 1] == '4') { ...
### 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(void) { string s; cin >> s; if (s[0] != '1') { cout << "NO" << endl; return 0; } if (s.find("444") != string::npos) { cout << "NO" << endl; return 0; } for (auto c : s) { if (c != '1' && c != '4') { cout << "NO" << endl; ...
### 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; vector<int> element, element1; list<int> datal; stack<int> datas; queue<int> dataq; map<string, int> datam; set<int> datase; vector<int>::iterator itv; list<int>::iterator itl; map<string, int>::iterator itm; set<int>::iterator itse; int main() { int i, len; string text...
### 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() { long long int n; cin >> n; while (n) { if (n % 10 != 1 && n % 100 != 14 && n % 1000 != 144) { cout << "NO" << endl; break; } n /= 10; } if (!n) { cout << "YES" << endl; } }
### 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(0); cin.tie(0); cout.tie(0); string s; cin >> s; long long int f = 0; for (long long int i = 0; i < s.length(); i++) { if (s[i] == '1') f = 1; if (s[i] != '1' && s[i] != '4') { cout << "NO" << endl; re...
### 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() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); string s; cin >> s; int count = 0; for (int i = 0; i < s.length(); i++) { if (i < (s.length() - 2) && s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i += 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(int argc, char *argv[]) { char c, a[15], n = 0; do { c = getchar(); if (c != '\n') { n++; a[n] = c; } } while (c != '\n'); int i = n, flag = 0; for (int i = 1; i <= n; i++) if (a[i] != '1' && a[i] != '4') flag++; while (i > 0...
### 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, a = "aaa"; long long l, l1 = 0; cin >> s; l = s.size(); s += a; for (int i = 0; i < l; i++) { if ((s[i] == '1') && (s[i + 1] == '4') && (s[i + 2] == '4')) { l1 += 3; i += 2; } else if ((s[i] == '1') && (s[i + 1] == '4')...
### 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; const int MX = 11; int n, l; int main() { scanf("%d", &n); while (n) { int a = n % 10; int b = n % 100; int c = n % 1000; if (a == 1) n /= 10; else if (b == 14) n /= 10; else if (c == 144) n /= 100; l++; if (l > 1000) { ...
### 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 n; cin >> n; for (long long i = 0; i < n.size(); i++) { if (n[i] != '1' && n[i] != '4') { cout << "NO" << endl; return 0; } } if (n[0] == '4') { cout << "NO" << endl; return 0; } int aux = 0; bool flag = false;...
### 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 s; cin >> s; long long int n = s.length(); long long int i = 0; long long int c = 0; while (i < n) { 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; ...
### 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() { ios_base::sync_with_stdio(false); cin.tie(NULL); string str; cin >> str; long long i = str.length() - 1; while (i >= 0) { if (str[i] == '1') { i--; continue; } if (i - 1 >= 0 && str[i] == '4' && str[i - 1] == '1') { 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; int main() { bool b = 0; string s; cin >> s; for (int i = 0; i < s.size(); ++i) { if (s[i] != '1' && s[i] != '4') { cout << "NO"; return 0; } } if (s.find("444") != s.npos || s[0] == '4') cout << "NO"; else cout << "YES"; 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; long long const MAXA = (long long)1e9 + 1; int main() { string s; cin >> s; if (s[0] != '1') { cout << "NO\n"; return 0; } for (long long i = 0; i < s.length(); i++) { if (!(s[i] == '4' || s[i] == '1')) { cout << "NO\n"; return 0; } ...
### 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; vector<int> a; while (n) { a.push_back(n % 10); n = n / 10; } reverse(a.begin(), a.end()); for (vector<int>::iterator it = a.begin(); it != a.end(); it++) { if ((it + 1) != a.end() && (it + 2) != a.end() && *(it) == 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 i, j, l, count{0}; string s; cin >> s; l = s.size(); for (i = 0; i < l; i++) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') { i = i + 2; continue; } else if (s[i] == '1' && s[i + 1] == '4') { i = i + 1; co...
### 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() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); string n; cin >> n; for (int i = 0; i < n.size(); i++) { if (n[0] != '1' || n[i] != '4' && n[i] != '1' || n[i] == '4' && i != n.size() - 1 && n[i + 1] == '4' && i != 0 && n[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() { 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 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, j, len, temp = 0; char str[123456]; cin >> str; len = strlen(str); for (i = 0; i < len; i++) { if (str[i] == '1' && str[i + 1] == '4' && str[i + 2] == '4') i = i + 2; else if (str[i] == '1' && str[i + 1] == '4') i++; els...
### 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(int argc, char const *argv[]) { string s; cin >> s; bool yes = true; for (long long i = 0; i < s.length();) { if (s[i] == '1' && s[i + 1] == '4' && s[i + 2] == '4') i += 3; else if (s[i] == '1' && s[i + 1] == '4') i += 2; else 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> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; int cnt4 = 0; while (N) { int cifra = N % 10; N = N / 10; if (cifra == 1) { cnt4 = 0; continue; } if (cifra == 4 && cnt4 < 2) { cnt4++; 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 a; int f, i; cin >> a; for (i = 0; i < a.length(); i++) if (a[i] != '1' and a[i] != '4') goto l; while ((f = a.find("144")) != -1) { for (i = f; i < f + 3; i++) a[i] = '*'; } while ((f = a.find("14")) != -1) { for (i = f; i < f ...
### 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_base::sync_with_stdio(false); string s; cin >> s; long t = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '1') continue; if (s[i] == '4' and s[i - 1] == '1') continue; if (s[i] == '4' and s[i - 1] == '4' and s[i - 2] == '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; long long MOD = 1e9 + 7; void solve() {} int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; string s; cin >> s; if (s[0] != '1') { cout << "NO"; } else { int mx = 0; for (int i = 0; i < s.length(); ++i) { if (s[...
### 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; vector<int> v; void digit(int n) { while (n != 0) { v.push_back(n % 10); n = n / 10; } } int main() { int n; scanf("%d", &n); digit(n); int sz = v.size(); int cnt4 = 0; for (int i = sz - 1; i >= 0; i--) { if (v[sz - 1] != 1) { printf("NO\n"...
### 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; const long long MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7; long long pw(long long te, long long tee) { if (tee == 0) return 1; long long res = pw(te, tee / 2); return (tee % 2 ? te * res * res : res * res); } string s; void Read_input() { cin >> s; } void Solve() { ...
### 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; bool ok = true; long long int n = s.size(); for (int i = 0; i < n; i++) { if (s[i] != '4' && s[i] != '1') ok = false; if (s[0] != '1') ok = false; if (s[i] == '4' && s[i + 1] == '4' && s[i + 2] == '4') ok = false; } ...
### 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...