using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;namespace P20{ class Tools { public static Random random = new Random(); public static void solve(double a, double b, double c, int count, int money) { for (int x = 0; x <= count; x++) for (int y = 0; y <= count - x; y++) { int z = count - x - y; if (Math.Abs(a * x + b * y + c * z - money) <= 1E-8) Console.WriteLine("{0} {1} {2}", x, y, z); } } public static bool prime(int n) { for (int c = 2; c * c <= n; c++) if (n % c == 0) return false; return true; } public static bool imply(bool p, bool q) { return !p || q; } public static bool int2bool(int x) { return x != 0; } public static int bool2int(bool x) { return x ? 1 : 0; } } class P01 { public void solve(int start, int end, int target) { int cur = Tools.random.Next(start, end); while (cur != target) { Console.Write("{0} ", cur); cur = Tools.random.Next(start, end); } Console.WriteLine("{0} ", cur); } } class P02 { public void solve(int start, int end, int mod) { int res = 0; for (int i = start; i <= end; i++) if (i % mod == 0) res += i; Console.WriteLine(res); } } class P03 { public void solve(int level) { for (int i = 1; i <= level; i++) { for (int j = 1; j <= level - i; j++) Console.Write(' '); for (int j = 1; j <= i; j++) Console.Write(j); for (int j = i - 1; j >= 1; j--) Console.Write(j); Console.WriteLine(); } for (int i = level - 1; i >= 1; i--) { for (int j = 1; j <= level - i; j++) Console.Write(' '); for (int j = 1; j <= i; j++) Console.Write(j); for (int j = i - 1; j >= 1; j--) Console.Write(j); Console.WriteLine(); } } } class P04 { public void solve() { Tools.solve(3, 2, 1.0 / 2, 100, 100); } } class P05 { public void solve() { Tools.solve(2, 4, 2.0 / 9, 100, 100); } } class P06 { const int N = 5; bool left(int p, int q) { return p + 1 == q || p == 5 && q == 1; } bool right(int p, int q) { return left(q, p); } bool near(int p, int q) { return left(p, q) || right(p, q); } public void solve() { int zhao = 1, qian, sun, li, zhou; for (qian = 2; qian <= N; qian++) for (sun = 2; sun <= N; sun++) for (li = 2; li <= N; li++) for (zhou = 2; zhou <= N; zhou++) if (qian == sun || qian == li || qian == zhou || sun == li || sun == zhou || li == zhou) continue; else { bool zp = left(zhao, qian), zq = left(sun, qian) || left(li, qian); bool lp = left(qian, sun), lq = near(li, sun); if (zp || zq || lp || lq) continue; else Console.WriteLine("{0} {1} {2} {3} {4}", zhao, qian, sun, li, zhou); } } } class P07 { public void solve() { for (int n = 100; n <= 999; n++) { int a = n / 100, b = (n / 10) % 10, c = n % 10; if (a != b && b != c && c != a && b > a + c && !Tools.prime(a + b)) Console.WriteLine(n); } } } class P08 { public void solve() { int a, b, c, d, e; for (int n = 0; n < 32; n++) { a = (n >> 4) & 1; b = (n >> 3) & 1; c = (n >> 2) & 1; d = (n >> 1) & 1; e = n & 1; if (a + b + c + d + e == 3 && a + c < 2 && b + c > 0 && Tools.imply(c == 1, d + e == 1) && b + c + d < 3 && Tools.imply(b == 1, d + e < 2)) Console.WriteLine("{0}{1}{2}{3}{4}", a, b, c, d, e); } } } class P09 { public void solve() { string line = Console.ReadLine(); String[] s = Regex.Split(line, "\\D+"); Console.WriteLine(s.Length); foreach (string t in s) if (t.Trim() != "") Console.WriteLine(t); } } class P10 { public void solve() { int a, b, c; for (a = 1; a <= 3; a++) for (b = 1; b <= 3; b++) for (c = 1; c <= 3; c++) { if (a == b || b == c || c == a) continue; bool ap = (b == 2 && c == 2), aq = a == 1; bool bp = (b <= 2), bq = (c == 3); bool cp = (a != 2), cq = (b != 1); if (a + Tools.bool2int(ap) + Tools.bool2int(aq) == 3 && b + Tools.bool2int(bp) + Tools.bool2int(bq) == 3 && c + Tools.bool2int(cp) + Tools.bool2int(cq) == 3) Console.WriteLine("{0} {1} {2}", a, b, c); } } } class P11 { const int N = 64; public void solve() { int a, b, c, d; for (a = N / 2; a <= N; a++) for (b = 0; b <= N - a; b++) for (c = 0; c <= N - a - b; c++) { d = N - a - b - c; int A = a, B = b, C = c, D = d; A -= B + C + D; B *= 2; C *= 2; D *= 2; B -= A + C + D; A *= 2; C *= 2; D *= 2; C -= A + B + D; A *= 2; B *= 2; D *= 2; D -= A + B + C; A *= 2; B *= 2; C *= 2; if (4 * A == N && 4 * B == N && 4 * C == N && 4 * D == N) Console.WriteLine("{0} {1} {2} {3}", a, b, c, d); } } } class P12 { public void solve() { String s = Console.ReadLine(); while (s.Length % 3 != 0) s = "0" + s; int d = s.Length / 3; int a = Int32.Parse(s.Substring(0, d)); int b = Int32.Parse(s.Substring(d, d)); int c = Int32.Parse(s.Substring(2 * d)); Console.WriteLine(a + c - b); } } class P13 { public void solve() { String s = Console.ReadLine(); String[] ws = Regex.Split(s, "\\W+"); foreach (String w in ws) if (s.Trim() != "") Console.WriteLine(w); } } class P14 { public void solve() { int a, b, c, d; for (int n = 0; n < 16; n++) { a = (n >> 3) & 1; b = (n >> 2) & 1; c = (n >> 1) & 1; d = n & 1; bool za = Tools.int2bool(d); bool zb = Tools.int2bool(c); bool zc = c == 0; bool zd = !zc; if (Tools.bool2int(za) + Tools.bool2int(zb) + Tools.bool2int(zc) + Tools.bool2int(zd) == 2 && a + b + c + d == 1) Console.WriteLine("{0} {1} {2} {3}", a, b, c, d); } } } class P15 { public void solve(int n) { int[] fish = new int[n + 1]; fish[0] = 1; for (int i = 1; i < n; i++) fish[i] = (n * fish[i - 1] + 1); Console.WriteLine(fish[n - 1]); } } class P16 { public void solve() { for (int m = 10; m <= 99; m++) { int s = 0; for (int n = m; n > 0; n /= 10) s += n % 10; if (m % s == 0) Console.WriteLine(m); } } } class P17 { public void solve() { for (int x = 6; ; x += 10) { int y = Int32.Parse("6" + (x / 10)); if (y == 4 * x) { Console.WriteLine(x + " " + y); break; } } } } class P18 { int f(int n, int d) { int tot = 0; for (; n > 0; n /= 10) if (n % 10 == d) ++tot; return tot; } public void solve(int count, int digit) { int tot = 0, page; for (page = 1; tot < count; page++) tot += f(page, digit); if (count == tot) Console.WriteLine(page); else Console.WriteLine("Something Wrong"); } } class P19 { public void solve() { String[] s = Console.ReadLine().Split(); int a = Int32.Parse(s[0]); int b = Int32.Parse(s[1]); int c = a + b; Console.WriteLine(" {0:d8}\n+{1:d8}\n--------\n {2:d8}", a, b, c); } } class P20 { public void solve() { Tools.solve(3, 2, 1, 30, 50); } } class Program { static void Main(string[] args) { new P01().solve(1, 100, 50); new P02().solve(1, 1000, 3 * 5); new P03().solve(3); new P04().solve(); new P05().solve(); new P06().solve(); new P07().solve(); new P08().solve(); new P09().solve(); new P10().solve(); new P11().solve(); new P12().solve(); new P13().solve(); new P14().solve(); new P15().solve(5); new P16().solve(); new P17().solve(); new P18().solve(202, 1); new P19().solve(); new P20().solve(); } }}
P20@C#
最新推荐文章于 2024-09-07 20:15:38 发布