ben phốt
NguyenAnhQuan
c_cpp
2 years ago
570 B
5
Indexable
#include <iostream> using namespace std; #define MAX 100 void Nhapmang(int a[], int n) { for (int i = 1; i <= n; i++) cin >> a[i]; } bool check(int n, int x) { while (n >= 10) n /= 10; return (n == x); } bool isBenford(int a[], int n) { int cnt1 = 0, cnt4 = 0; for (int i = 1; i <= n; i++) if (check(a[i], 1)) cnt1++; else if (check(a[i], 4)) cnt4++; return ((cnt1 == 3 && cnt4 == 1) ? 1 : 0); } int main() { int a[MAX], n = 10; Nhapmang(a, n); if (isBenford(a, n) == true) cout << "TRUE" << endl; else cout << "FALSE" << endl; return 0; }
Editor is loading...
Leave a Comment