1 solutions
-
0
C++ :
/* ID: jhqwan1 PROG: crypt1 LANG: C++11 */ #include <fstream> #include <iostream> using namespace std; int n, s[10], a, b, c, d, e, ans = 0; ifstream fin("crypt1.in"); ofstream fout("crypt1.out"); //#define cin fin //#define cout fout bool yes; inline void bao(); main() { cin >> n; for (int i = 1; i <= n; ++i) cin >> s[i]; bao(); cout << ans; // for(;;); } inline void bao(){ for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) for (int k = 1; k <= n; ++k){ a = s[i] * 100 + s[j] * 10 + s[k]; for (int l = 1; l <= n; ++l) for (int m = 1; m <= n; ++m){ yes = 1; b = s[l] * 10 + s[m]; c = a * (b % 10); if (c < 100 || c > 999) continue; while (c > 0){ d = c % 10; c /= 10; int o; for (o = 1; o <= n; ++o) if (d == s[o]) break; if (o > n){ yes = 0; break; } } if (! yes) continue; d = a * (b / 10); if (d < 100 || d > 999) continue; while (d > 0){ e = d % 10; d /= 10; int o; for (o = 1; o <= n; ++o) if (e == s[o]) break; if (o > n){ yes = 0; break; } } if (! yes) continue; e = a * b; if (e < 1000 || e > 9999) continue; while (e > 0){ c = e % 10; e /= 10; int o; for (o = 1; o <= n; ++o) if (c == s[o]) break; if (o > n){ yes = 0; break; } } if (! yes) continue; ans++; } } }Pascal :
var i,j,k,m,n,bg,ji,p,q,s,t,a,b,x,max:longint; num:array[0..9] of boolean; begin {assign(input,'crypt.in'); reset(input); assign(output,'crypt.out'); rewrite(output);} fillchar(num,sizeof(num),false); readln(n); for i:=1 to n do begin read(m); num[m]:=true; end; for i:=1 to 9 do if num[i] then for j:=1 to 9 do if num[j] then for k:=1 to 9 do if num[k] then begin s:=i*100+j*10+k; for p:=1 to 9 do if num[p] then for q:=1 to 9 do if num[q] then begin ji:=p*10+q; t:=s*q; a:=s*p; b:=s*ji; if (t<=999) and (a<=999) and (b<=9999) then begin bg:=0; repeat x:=t mod 10; if not num[x] then begin bg:=1;break;end; t:=t div 10; until t=0; repeat x:=a mod 10; if not num[x] then begin bg:=1;break;end; a:=a div 10; until a=0; repeat x:=b mod 10; if not num[x] then begin bg:=1;break;end; b:=b div 10; until b=0; if bg=0 then inc(max); end; end; end; writeln(max); {close(input); close(output);} end.
- 1
Information
- ID
- 16880
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By