@jtahstu
2015-09-07T12:22:49.000000Z
字数 36385
阅读 4896
C# ACM Code
有代码的都是AC了的,没AC的只有个题目,以后假如AC了再把代码加上去
using System;class Acm1000{static void Main(){string[] ss = Console.ReadLine().Split();Console.WriteLine(long.Parse(ss[0]) + long.Parse(ss[1]));}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1001 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int a = int.Parse(s[0]), b = int.Parse(s[1]);if (a == 0 && b == 0) break;long ans = (a + b) * (b - a + 1) / 2;Console.WriteLine(ans);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1002 {class Program {static void Main(string[] args) {string sb;int jtahstu = 0;while ((sb = Console.ReadLine()) != null) {int count = 0;for (int k = 0; k < 11; k++) {if (sb[k] == '6' || sb[k] == '8')count++;if (sb[k] == '4') { count = 0; break; }}if (count > 4) {Console.WriteLine(sb);jtahstu++;}}Console.WriteLine(jtahstu);//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1003 {/// <summary>/// 大数阶乘/// 本代码参考老赵以前写过的大数阶乘代码/// </summary>class Program {static void Main(string[] args) {string sb;int i, j, temp, start, sc, N = 1200;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);int[] a = new int[N];for (a[0] = 1, i = 1; i <= n; i++)for (sc = 0, j = 0; j < N; j++) {temp = a[j] * i + sc;//当前这一位的数乘上i,然后加上后面来的进位sc = temp / 10;//sc代表进位a[j] = temp % 10;//本位保留模后的结果}//数据是倒着存的,即1*2*3*4=24,存是是按420000000...保存的,一直有N=1200位for (start = N - 1; a[start] == 0; --start) ;//这里是确定从后面哪一位开始输出,从后向前输出for (; start >= 0; --start)Console.Write(a[start]);Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1004 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string[] sb = Console.ReadLine().Split();int m = int.Parse(sb[0]);int[] a = new int[105];for (int i = 1; i <= m; i++)a[i] = int.Parse(sb[i]);Array.Sort(a, 1, m);int d = a[2] - a[1];bool flag = true;for (int i = 3; i <= m; i++)if (a[i] - a[i - 1] != d) {flag = false;Console.WriteLine("no");break;}if (flag)Console.WriteLine("yes");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1005 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string[] sb = Console.ReadLine().Split();int a = int.Parse(sb[0]), b = int.Parse(sb[1]), c = int.Parse(sb[2]);int min = a;int max = a;if (b < min) min = b;if (b > max) max = b;if (max / min == c)Console.WriteLine("{0}/{1}={2}", max, min, c);else if (max - min == c)Console.WriteLine("{0}-{1}={2}", max, min, c);else if (max + min == c)Console.WriteLine("{0}+{1}={2}", max, min, c);else if (max * min == c)Console.WriteLine("{0}*{1}={2}", max, min, c);elseConsole.WriteLine("None");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1006 {class Program {static void Main(string[] args) {string[] s = Console.ReadLine().Split();int min = 10000000, max = -10000000;for (int i = 0; i < 5; i++) {int temp = int.Parse(s[i]);if (temp > max) max = temp;if (temp < min) min = temp;}Console.WriteLine("{0} {1}", min, max);}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1007 {class Program {static void Main(string[] args) {int[] fib = new int[25];fib[1] = 1; fib[2] = 1;for (int i = 3; i < 21; i++)fib[i] = fib[i - 1] + fib[i - 2];int n = int.Parse(Console.ReadLine());while (n-- > 0) {int x = int.Parse(Console.ReadLine());Console.WriteLine(fib[x]);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1008 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string s = Console.ReadLine();for (int i = 0; i < s.Length; i++) {if (s[i] >= 'a' && s[i] <= 'z')Console.Write(s[i].ToString().ToUpper());elseConsole.Write(s[i].ToString().ToLower());}Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1009 {class Program {static int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}static int lcm(int a, int b) {return a / gcd(a, b) * b;}static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string[] sb = Console.ReadLine().Split();int a = int.Parse(sb[0]), b = int.Parse(sb[1]);Console.WriteLine("{0} {1}", gcd(a, b), lcm(a, b));}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1010 {/// <summary>/// 貌似叫扩展欧几里得定理,题目我都没看,代码已看不懂/// WA了,以后再来改吧/// </summary>class Program {static long x, y, m, n, l;static long ect_gcd(long a, long b, long x, long y) {long tmp, ret;if (b == 0) {x = 1; y = 0;return a;}ret = ect_gcd(b, a % b, x, y);tmp = x; x = y; y = tmp - a / b * y;return ret;}static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {string[] sb = s.Split();x = long.Parse(sb[0]); y = long.Parse(sb[1]); m = long.Parse(sb[2]); n = long.Parse(sb[3]); l = long.Parse(sb[4]);long a = n - m, b = l, c = x - y;long d = ect_gcd(a, b, x, y);if (c % d != 0) {Console.WriteLine("Impossible");continue;}x = (x * c / d) % (b / d);if (x < 0) x += b / d;Console.WriteLine(x);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1011 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());int[] ans = new int[n * n + n + 10];string s;int k = 1;while ((s = Console.ReadLine()) != null) {string[] ss = s.Split();int a = int.Parse(ss[0]);int b = int.Parse(ss[1]);for (int i = 0 ; i < b ; i++)ans[k++] = a;}for (int i = 1 ; i <= n * n ; i++) {Console.Write(ans[i] + " ");if (i % n == 0)Console.WriteLine();}//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1012 {class Program {static void Main(string[] args) {string s;string[] str = { "0000" , "0001" , "0010" , "0011" , "0100" , "0101" , "0110" , "0111" , "1000" , "1001" , "1010" , "1011" , "1100" , "1101" , "1110" , "1111" };while ((s = Console.ReadLine()) != null) {for (int i = 0 ; i < s.Length ; i++) {if (s[i] >= '0' && s[i] <= '9')Console.Write(str[s[i] - '0']);elseConsole.Write(str[s[i] - 'A' + 10]);}Console.WriteLine();}}}}//long n = Convert.ToInt64(s , 16);//string ans = Convert.ToString(n , 2);//Console.WriteLine(ans);
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1013 {class Program {static int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}static int lcm(int a, int b) {return a / gcd(a, b) * b;}static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {string[] a = s.Split();int a1 = int.Parse(a[0]), b1 = int.Parse(a[1]), a2 = int.Parse(a[2]), b2 = int.Parse(a[3]);for (int i = 1; i <= lcm(a1, a2); i++)//实际这样写我感觉是不合理的,但是AC了,怎么能求最小公倍数呢,i don't know!if (i % a1 == b1 && i % a2 == b2) { Console.WriteLine(i); break; }}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1014 {class Program {static bool prime(int n)//判断素数{if (n == 1) return false;if (n == 2) return true;for (int i = 2; i * i <= n; i++)if (n % i == 0) return false;return true;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);for (int i = n / 2; i > 0; i--) {if (prime(i) && prime(n - i)) {Console.WriteLine("{0} {1}", i, n - i);break;}}}}}}
1015 最简单的编程语言
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1016 {class Program {static void Main(string[] args) {string jt;while ((jt = Console.ReadLine()) != null) {string[] s = jt.Split();int n = int.Parse(s[0]), m = int.Parse(s[1]);if (m + n == 0) break;if (m == 0 && n != 0) { Console.WriteLine(n - 1); continue; }string[] b = Console.ReadLine().Split();int[] a = new int[205];int count = 1;a[int.Parse(b[0])] = count;a[int.Parse(b[1])] = count;for (int i = 1; i < m; i++) {string[] sb = Console.ReadLine().Split();int p = int.Parse(sb[0]), q = int.Parse(sb[1]);if (a[p] != 0) a[q] = count;else if (a[q] != 0) a[p] = count;else {count++;a[p] = count;a[q] = a[p];}}for (int i = 1; i <= n; i++)if (a[i] == 0)count++;Console.WriteLine(count - 1);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1017 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);bool flag = false;for (int i = -1400; i <= 1400; i++) {if (i * i * i == n) {flag = true;break;}}if (flag)Console.WriteLine("YES");elseConsole.WriteLine("NO");//if (n < 0) n = -n;//int x = (int)Math.Pow(n, 1.0/3);////x = Math.Floor(x);////Console.WriteLine(x);//if (x * x * x == n)// Console.WriteLine("YES");//else// Console.WriteLine("NO");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1018 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);int[] a = new int[10005];string[] s = Console.ReadLine().Split();for (int i = 0; i < n; i++)a[i] = int.Parse(s[i]);int count = 1;for (int i = 1; i < n; i++) {if (a[i] == a[i - count])count++;}Console.WriteLine(count);}}}}
1019 还有多少桌面
1020 严格递增序列
1021 最后的胜利者
1022 快乐指数
1023 DNA Sorting
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1024 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int a = int.Parse(s[0]), b = int.Parse(s[1]);if (a == 0 && b == 0) break;else Console.WriteLine(a + b);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1025 {class Program {static string convert(string s) {string ans = "22233344455566670778889990";char[] ss = new char[50];int k = 0;for (int i = 0; i < s.Length; i++) {if (s[i] >= '0' && s[i] <= '9') { ss[k++] = s[i]; }if (s[i] >= 'A' && s[i] <= 'Z') { ss[k++] = ans[s[i] - 'A']; }}string st = new string(ss);return st.Substring(0, 3) + "-" + st.Substring(3, 4);}static void Main(string[] args) {int n = int.Parse(Console.ReadLine());string[] s = new string[n + 5];for (int i = 0; i < n; i++)s[i] = convert(Console.ReadLine());Array.Sort(s, 0, n);//for (int i = 0; i < n; i++)// Console.WriteLine(s[i]);int j = 0;string[] ans = new string[n];int[] an = new int[n];ans[0] = s[0];an[0] = 1;for (int i = 1; i < n; i++) {if (s[i] != s[i - 1]) {j++;ans[j] = s[i];an[j]++;} else {an[j]++;}}for (int i = 0; i < j; i++) {if (an[i] > 1) {Console.WriteLine(ans[i] + " " + an[i]);}}//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1026 {class Program {static void Main(string[] args) {string[] s = Console.ReadLine().Split();int m = int.Parse(s[0]), n = int.Parse(s[1]);int count = 0;for (int i = m; i <= n; i++)if (i % 15 == 0)count++;Console.WriteLine(count);}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1027 {class Program {static void Main(string[] args) {long n = long.Parse(Console.ReadLine());long sum = 0, temp = n;while (n > 0) {sum += n % 10;n /= 10;}if (temp % sum == 0)Console.WriteLine("Lucky Word");elseConsole.WriteLine("No Answer");}}}
1028 单词分隔
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1029 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());char[] stack = new char[10005];while (n-- > 0) {string s = Console.ReadLine();int i, l = s.Length, j = 0, flag = 1;for (i = 0; i < l; i++) {if (s[i] == '(' || s[i] == '[')stack[j++] = s[i];if (s[i] == ')') {if (stack[j - 1] == '(') {j--;flag = 1;} elseflag = 0;}if (s[i] == ']') {if (stack[j - 1] == '[') {j--;flag = 1;} elseflag = 0;}if (flag == 0) break;}if (flag == 1 && j == 0)Console.WriteLine("Yes");elseConsole.WriteLine("No");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1030 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string s = Console.ReadLine();int[] a = new int[3];for (int i = 0; i < 3; i++)a[i] = s[i] - 'a';Array.Sort(a);Console.WriteLine("{0} {1} {2}", (char)(a[0] + 'a'), (char)(a[1] + 'a'), (char)(a[2] + 'a'));}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1031 {class Program {static bool prime(int n) {if (n == 1) return false;if (n == 2) return true;for (int i = 2; i * i <= n; i++)if (n % i == 0)return false;return true;}static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {int m = int.Parse(Console.ReadLine());string[] s = Console.ReadLine().Split();int sum = 0;for (int i = 0; i < m; i++)if (prime(int.Parse(s[i])))sum += int.Parse(s[i]);Console.WriteLine(sum);}//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1032 {class Program {static bool jtahstu(int n) {int x = n % 10, y = n / 10 % 10, z = n / 100;if (x * x * x + y * y * y + z * z * z == n) return true;return false;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);if (n == 0) break;if (jtahstu(n))Console.WriteLine("Yes");elseConsole.WriteLine("No");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1033 {class Program {static void Main(string[] args) {int t = int.Parse(Console.ReadLine());while (t-- > 0) {string[] sb = Console.ReadLine().Split();int n = int.Parse(sb[0]), m = int.Parse(sb[1]);int x = 2 * n - m / 2, y = m / 2 - n;if (x + y == n && 2 * x + 4 * y == m && x >= 0 && y >= 0)Console.WriteLine("{0} {1}", x, y);elseConsole.WriteLine("No answer");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1034 {class Program {static void Main(string[] args) {string[] sb = Console.ReadLine().Split();double x = double.Parse(sb[0]), y = double.Parse(sb[1]), z = double.Parse(sb[2]);double area = (x + y) * z / 2;double perimeter = x + y + Math.Sqrt(4 * z * z + (y - x) * (y - x));Console.WriteLine(area.ToString("0.00"));Console.WriteLine(perimeter.ToString("0.00"));}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1035 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {Console.WriteLine(sb);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1036 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {int m = int.Parse(Console.ReadLine());int[] a = new int[32];int i = 0;while (m > 0) {a[i] = m % 2;m /= 2;i++;}for (int j = 31; j >= 0; j--)Console.Write(a[j]);Console.WriteLine();}}}}
1037 八皇后问题
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1038 {class Program {static bool judge(int n)//判断数字是否包含0{if (n == 0) return true;while (n > 0) {if (n % 10 == 0) return true;n /= 10;}return false;}static int fuck(int n)//十进制转九进制{int sum = 0, i = 1;while (n > 0) {sum = sum + n % 10 * i;n /= 10;i *= 9;}return sum;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);if (judge(n))Console.WriteLine("Unlucky");elseConsole.WriteLine(fuck(n));}}}}
1039 单目标0/1背包问题
1040 用动态规划求解矩阵乘法链问题
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1041 {/// <summary>/// 哈哈,这个方法就问你6不6/// </summary>class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());int x1, x2, x3, x4, x5, x6, x7;x1 = n / 100;n = n % 100;x2 = n / 50;n = n % 50;x3 = n / 20;n = n % 20;x4 = n / 10;n = n % 10;x5 = n / 5;n = n % 5;x6 = n / 2;n = n % 2;x7 = n;for (int i = 0; i < x1; i++)Console.WriteLine("100");for (int i = 0; i < x2; i++)Console.WriteLine("50");for (int i = 0; i < x3; i++)Console.WriteLine("20");for (int i = 0; i < x4; i++)Console.WriteLine("10");for (int i = 0; i < x5; i++)Console.WriteLine("5");for (int i = 0; i < x6; i++)Console.WriteLine("2");for (int i = 0; i < x7; i++)Console.WriteLine("1");}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1042 {class Program {static long f(long a)//2进制转换成10进制{long s = 0, j = 1;while (a > 0) {s += (a % 10) * j;a = a / 10;j = j * 2;}return s;}static long g(long s)//10进制转换成2进制{long j = 1, n = 0;while (s > 0) {n += (s % 2) * j;s = s / 2;j *= 10;}return n;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();long a = long.Parse(s[0]), b = long.Parse(s[2]);if (s[1] == "+")Console.WriteLine(g(f(a) + f(b)));elseConsole.WriteLine(g(f(a) - f(b)));}}}}
1043 n个人的工作分配
1044 用分枝定界法求解TSP问题
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1045 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());string[] s = Console.ReadLine().Split();int[] a = new int[210];for (int i = 0; i < n; i++)a[i] = int.Parse(s[i]);Array.Sort(a, 0, n);Console.WriteLine(a[0]);for (int i = 1; i < n; i++)if (a[i] != a[i - 1])Console.WriteLine(a[i]);//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1046 {class Program {static void Main(string[] args) {string s = Console.ReadLine();string[] ss = s.Split();Console.WriteLine(ss.Length);Array.Sort(ss, 0, ss.Length);int j = 0;string[] ans = new string[ss.Length];int[] an = new int[ss.Length];ans[0] = ss[0];an[0] = 1;for (int i = 1; i < ss.Length; i++) {if (ss[i] != ss[i - 1]) {j++;ans[j] = ss[i];an[j]++;} else {an[j]++;}}for (int i = 0; i <= j; i++)Console.WriteLine(ans[i] + ":" + an[i]);//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1047 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());int jt = int.Parse(Console.ReadLine());string[] s = Console.ReadLine().Split();int[] a = new int[1005];for (int i = 0; i < n; i++)a[i] = int.Parse(s[i]);Array.Sort(a, 0, n);if (jt == 0) {for (int i = 0; i < n; i++)Console.WriteLine(a[i]);} else {for (int i = n - 1; i >= 0; i--)Console.WriteLine(a[i]);}//Console.ReadLine();}}}
1048 求某一整数序列的全排列问题
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1049 {class Program {static int[,] a = new int[101, 101];static void f(int n)//翻转90度{for (int j = n - 1; j >= 0; j--) {for (int i = 0; i < n; i++) {Console.Write("{0} ", a[i, j]);}Console.WriteLine();}}static void g(int n)//翻转180度{for (int i = n - 1; i >= 0; i--) {for (int j = n - 1; j >= 0; j--) {Console.Write("{0} ", a[i, j]);}Console.WriteLine();}}static void h(int n)//翻转270度{for (int i = 0; i < n; i++) {for (int j = n - 1; j >= 0; j--) {Console.Write("{0} ", a[j, i]);}Console.WriteLine();}}static void Main(string[] args) {int n = int.Parse(Console.ReadLine());int m = int.Parse(Console.ReadLine());for (int i = 0; i < n; i++) {string[] s = Console.ReadLine().Split();for (int j = 0; j < n; j++) {a[i, j] = int.Parse(s[j]);}}if (m == 1)f(n);if (m == 2)g(n);if (m == 3)h(n);//Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1050 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string str = Console.ReadLine();int s = 0, s1 = 0;for (int i = 0; i < str.Length; i++) {if (str[i] == '_') s++;if (str[i] >= '0' && str[i] <= '9' && i != 0 || str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z')s1++;}if (s + s1 == str.Length)Console.WriteLine("yes");elseConsole.WriteLine("no");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1051 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {Console.Write(sb[0].ToString().ToUpper());for (int i = 1; i < sb.Length; i++)if (sb[i - 1] == ' ')Console.Write(sb[i].ToString().ToUpper());elseConsole.Write(sb[i]);Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1052 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string sb = Console.ReadLine();int count = 0;for (int i = 0; i < sb.Length; i++)if (sb[i] >= '0' && sb[i] <= '9')count++;Console.WriteLine(count);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1053 {class Program {static void Main(string[] args) {string sb;int i, j, temp, start, sc, N = 1200;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);int[] a = new int[N];for (a[0] = 1, i = 1; i <= n; i++)for (sc = 0, j = 0; j < N; j++) {temp = a[j] * i + sc;//当前这一位的数乘上i,然后加上后面来的进位sc = temp / 10;//sc代表进位a[j] = temp % 10;//本位保留模后的结果}//数据是倒着存的,即1*2*3*4=24,存是是按420000000...保存的,一直有N=1200位for (start = N - 1; a[start] == 0; --start) ;//这里是确定从后面哪一位开始输出,从后向前输出for (; start >= 0; --start)Console.Write(a[start]);Console.WriteLine();}}}}
1054 求逆序数
1055 矩阵乘法
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1056 {class Program {static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {string[] b = s.Split();int[] a = new int[6];for (int i = 0; i < 6; i++)a[i] = int.Parse(b[i]);if (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] == 0) break;int c = a[2] - a[0], d = a[3] - a[1], e = a[4] - a[2], f = a[5] - a[3];if (c * f - d * e > 0)Console.WriteLine("0");elseConsole.WriteLine("1");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1057 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int n = int.Parse(s[0]);double max = -100000000, min = 10000000, sum = 0;for (int i = 1; i <= n; i++) {sum += double.Parse(s[i]);if (double.Parse(s[i]) > max) max = double.Parse(s[i]);if (double.Parse(s[i]) < min) min = double.Parse(s[i]);}double average = (sum - max - min) / (n - 2);Console.WriteLine(average.ToString("0.00"));}}}}
1058 货币兑换
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1059 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int n = int.Parse(s[0]), m = int.Parse(s[1]);Console.Write("+");//第一行for (int i = 0; i < n; i++)Console.Write("-");Console.WriteLine("+");for (int i = 0; i < m; i++)//中间的|和空格{Console.Write("|");for (int j = 0; j < n; j++)Console.Write(" ");Console.WriteLine("|");}Console.Write("+");//最后一行,和第一行一样for (int i = 0; i < n; i++)Console.Write("-");Console.WriteLine("+");Console.WriteLine();}}}}
1060 取个标题好难
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1061 {class Program {static int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}static int lcm(int a, int b) {return a / gcd(a, b) * b;}static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {string[] sb = s.Split();int n = int.Parse(sb[0]);int sum = 1;for (int i = 1; i <= n; i++)sum = lcm(sum, int.Parse(sb[i]));Console.WriteLine(sum);}}}}
1062 最左边一位数
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1063 {class Program {static int f(int n)//该函数由Problem_1041改编而来{int[] b = { 100, 50, 10, 5, 2, 1 }; //开数组,储存币种int kk;int count = 0;for (int i = 0; i < 6; i++) {kk = n / b[i];//除即可得kk张面值为a[i]的零钱n %= b[i];count += kk;}return count;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int n = int.Parse(sb);if (n == 0) break;string[] s = Console.ReadLine().Split();int sum = 0;for (int i = 0; i < n; i++) {int x = int.Parse(s[i]);sum += f(x);}Console.WriteLine(sum);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1064 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int x = int.Parse(s[0]), y = int.Parse(s[1]);Console.WriteLine(x + y);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1065 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string[] sb = Console.ReadLine().Split();int x = int.Parse(sb[0]), y = int.Parse(sb[1]);Console.WriteLine(x + y);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1066 {/// <summary>/// 表示这条道题我很郁闷,又是一直RE/// what's a fuck/// </summary>class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int n = int.Parse(s[0]);if (n == 0) break;int sum = 0;for (int i = 1; i <= n; i++)sum += int.Parse(s[i]);Console.WriteLine(sum);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1067 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int x = int.Parse(s[0]), y = int.Parse(s[1]);if (x == 0 && y == 0) break;Console.WriteLine(x + y);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1068 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string[] s = Console.ReadLine().Split();int t = int.Parse(s[0]);int sum = 0, i = 1;while (t-- > 0) {sum += int.Parse(s[i]);i++;}Console.WriteLine(sum);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1069 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int n = int.Parse(s[0]);//if (n == 0) break;int sum = 0, i = 1;while (n-- > 0) {sum += int.Parse(s[i]);i++;}Console.WriteLine(sum);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1070 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int x = int.Parse(s[0]), y = int.Parse(s[1]);Console.WriteLine(x + y);Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1071 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string[] s = Console.ReadLine().Split();int t = int.Parse(s[0]);int sum = 0, i = 1;while (t-- > 0) {sum += int.Parse(s[i]);i++;}Console.WriteLine(sum);Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1072 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {long n = long.Parse(sb);long sum = (1 + n) * n / 2;Console.WriteLine(sum);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1073 {class Program {static void Main(string[] args) {string sn;while (!(sn = Console.ReadLine()).Equals("0")) {int n = int.Parse(sn);string[] s = new string[n + 5];for (int i = 0 ; i < n ; i++)s[i] = Console.ReadLine();string axb = s[0];Array.Sort(s , 0 , n);int max = 1;int count = 1;int flag = 0;for (int i = 0 ; i < n ; i++) {count = 1;for (int j = i + 1 ; j < n ; j++) {if (s[j].Equals(s[i]))count++;elsebreak;}if (count > max) {max = count;flag = i;}}if (max == 1)//??????????????????????????????????????????????????????????????Console.WriteLine(axb);elseConsole.WriteLine(s[flag]);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1074 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int n = int.Parse(s[0]), m = int.Parse(s[1]);if (n + m == 0) break;int ans = 1;for (int i = 1; i <= m; i++) {ans *= n;ans %= 1000;}Console.WriteLine(ans);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1075 {class Program {static bool leapyear(int n) {if ((n % 4 == 0 && n % 100 != 0) || n % 400 == 0)return true;return false;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {int x = 0, y = 0;//前面这一大串就是要解决输入问题,真尼玛坑for (int i = 0; i < sb.Length; i++) {if (sb[i] == '/' && x == 0)x = i;if (sb[i] == '/' && x != 0)y = i;}int year = int.Parse(sb.Substring(0, x));int month = int.Parse(sb.Substring(x + 1, y - x - 1));int day = int.Parse(sb.Substring(y + 1, sb.Length - y - 1));//Console.WriteLine(year + " " + month + " " + day);int[] a = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//非闰年int[] b = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };//闰年int sum = 0;if (leapyear(year)) {for (int i = 0; i < month - 1; i++)sum += b[i];sum += day;} else {for (int i = 0; i < month - 1; i++)sum += a[i];sum += day;}Console.WriteLine(sum);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1076 {class Program {static void Main(string[] args) {int t = int.Parse(Console.ReadLine());while (t-- > 0) {int c = 1;string s = Console.ReadLine();for (int i = 1; i < s.Length; i++) {if (s[i] == s[i - 1]) ++c;else {if (c > 1)Console.Write(c);Console.Write(s[i - 1]);c = 1;}}if (s[s.Length - 1] == s[s.Length - 2])Console.Write("{0}{1}", c, s[s.Length - 2]);elseConsole.Write(s[s.Length - 1]);Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1077 {/// <summary>/// 找一个范围内转换次数最多的次数输出/// </summary>class Program {static int tsy(int a) {int count = 1;while (a != 1) {if (a % 2 == 1) { a = 3 * a + 1; count++; } else { a /= 2; count++; }}return count;}static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {string[] s = sb.Split();int n = int.Parse(s[0]), m = int.Parse(s[1]);int n1 = n, m1 = m;if (n > m) {int temp = m;m = n;n = temp;}int max = -1;for (int i = n; i <= m; i++) {int count = tsy(i);if (count > max) max = count;}Console.WriteLine("{0} {1} {2}", n1, m1, max);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1078 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {string sb = Console.ReadLine();int ans = int.Parse(sb) - (int)Math.Pow(10.0, sb.Length - 1) * (sb[0] - '0');Console.WriteLine(ans);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1079 {class Program {static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {int t = 0;bool falg = true;for (int i = 1; i <= s.Length; i++) {if (s.Length % i == 0 && falg) {string sb = s.Substring(0, i);int j = 0;for (j = i; j < s.Length; j += i) {string temp = s.Substring(j, i);if (temp != sb) {break;}}if (j == s.Length) { t = i; falg = false; break; }}}Console.WriteLine(t);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1080 {class Program {static void Main(string[] args) {int t = int.Parse(Console.ReadLine());while (t-- > 0) {string[] s = Console.ReadLine().Split();int n = int.Parse(s[0]);int[] a = new int[10001];for (int i = 1; i <= n; i++)a[int.Parse(s[i])]++;for (int i = 0; i < 10001; i++)if (a[i] != 0 && a[i] % 2 == 1) {Console.WriteLine(i);break;}}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1081 {class Program {static void Main(string[] args) {string s = Console.ReadLine();string b = Console.ReadLine();int x = int.Parse(Console.ReadLine());int n = (s[s.Length - 1] - '0') + (b[b.Length - 1] - '0');if (n % 10 == x)Console.WriteLine("YES");elseConsole.WriteLine("NO");//Console.ReadLine();}}}
1082 螺旋矩阵
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Text.RegularExpressions;namespace AK1083 {class Program {struct people {public string name;public double yin, zheng, shu, zhuan;public double zong;public double chu;public double fu;};public class MyComparer : IComparer<people> {int IComparer<people>.Compare(people x, people y) {if (x.zong == y.zong) {return x.name.CompareTo(y.name);}return x.zong < y.zong ? 1 : -1;}}static void Main(string[] args) {string[] s = Console.ReadLine().Split();double[] a = new double[5 + 2];for (int i = 0; i < 5; i++)a[i] = double.Parse(s[i]);string str;people[] sql = new people[205];int j = 0;while ((str = Console.ReadLine()) != null) {string[] ss = Regex.Split(str, @"\s+");sql[j].name = ss[0];sql[j].yin = double.Parse(ss[1]);sql[j].zheng = double.Parse(ss[2]);sql[j].shu = double.Parse(ss[3]);sql[j].zhuan = double.Parse(ss[4]);sql[j].chu = sql[j].yin + sql[j].zheng + sql[j].shu + sql[j].zhuan;sql[j].fu = double.Parse(ss[5]);sql[j].zong = sql[j].chu * 0.6 + sql[j].fu * 0.4;j++;}Array.Sort(sql, 0, j, new MyComparer());int rank = 1;for (int i = 0; i < j; i++) {if (sql[i].chu >= a[4] && sql[i].yin >= a[0] && sql[i].zheng >= a[1] && sql[i].shu >= a[2] && sql[i].zhuan >= a[3] && sql[i].fu >= 60)Console.WriteLine("{0} {1} {2} {3} {4}", sql[i].name, sql[i].chu, sql[i].fu, sql[i].zong.ToString("0.0"), rank++);}Console.ReadLine();}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1084 {class Program {static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {int count = 0;string b = Console.ReadLine();for (int i = 0; i < s.Length - b.Length + 1; i++) {string sb = s.Substring(i, b.Length);if (sb.Equals(b))count++;}Console.WriteLine(count);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1085 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {long n = long.Parse(sb);long count = 0;while (n > 0) {count += n % 2;n = n >> 1;}if (count % 2 == 0)Console.WriteLine("even");elseConsole.WriteLine("odd");}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1086 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {long n = long.Parse(sb);long i = 1, ans = 0;while (n > 0) {long temp = n % 2;ans = ans * 2 + temp;//摸出来的一次*2即可n = n / 2;}Console.WriteLine(ans);}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1087 {class Program {struct Time {public int start;public int end;}public class MyComparer : IComparer<Time> {int IComparer<Time>.Compare(Time a , Time b) {return a.end < b.end ? -1 : 1;}}static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {int n = int.Parse(s);Time[] a = new Time[n + 5];for (int i = 0 ; i < n ; i++) {string[] ss = Console.ReadLine().Split();a[i].start = int.Parse(ss[0]);a[i].end = int.Parse(ss[1]);}Array.Sort(a , 0 , n , new MyComparer());int count = 1 , temp = a[0].end;for (int i = 1 ; i < n ; i++) {if (a[i].start >= temp) {count++;temp = a[i].end;}}Console.WriteLine(count);}}}}
1088 输出二叉树
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1089 {class Program {static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {string[] sb = s.Split();int a = int.Parse(sb[0]), b = int.Parse(sb[1]), c = int.Parse(sb[2]);if (a + b + c == -3) break;else {bool flag = false;if (a <= 168) {flag = true;Console.WriteLine("CRASH {0}", a);}if (!flag && b <= 168) {flag = true;Console.WriteLine("CRASH {0}", b);}if (!flag && c <= 168) {flag = true;Console.WriteLine("CRASH {0}", c);}if (!flag)Console.WriteLine("NO CRASH");}}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1090 {class Program {static void Main(string[] args) {string sb;while ((sb = Console.ReadLine()) != null) {if (sb.Equals("END")) break;for (int i = 0; i < sb.Length; i++) {if (sb[i] == 'A' || sb[i] == 'W' || sb[i] == 'F') Console.Write("I");else if (sb[i] == 'C') Console.Write("L");else if (sb[i] == 'M') Console.Write("o");else if (sb[i] == 'S') Console.Write("v");else if (sb[i] == 'D' || sb[i] == 'P' || sb[i] == 'G' || sb[i] == 'B') Console.Write("e");else if (sb[i] == 'L') Console.Write("Y");else if (sb[i] == 'X') Console.Write("u");else Console.Write(sb[i]);}Console.WriteLine();}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1091 {class Program {static int fuck(int n) {int sum = 0;while (n > 0) {sum = sum * 10 + n % 10;n /= 10;}return sum;}static void Main(string[] args) {string s;while ((s = Console.ReadLine()) != null) {string[] sb = s.Split();int a = int.Parse(sb[0]), b = int.Parse(sb[1]);Console.WriteLine(fuck(fuck(a) * fuck(b)));}}}}
1092 整数变换问题
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK093 {class Program {struct Rectangle {public int len , wid , bian;}public class MyComparer : IComparer<Rectangle> {int IComparer<Rectangle>.Compare(Rectangle x , Rectangle y) {if (x.bian == y.bian) {if (x.len == y.len)return x.wid < y.wid ? -1 : 1;return x.len < y.len ? -1 : 1;}return x.bian < y.bian ? -1 : 1;}}static void Main(string[] args) {int n = int.Parse(Console.ReadLine());while (n-- > 0) {int m = int.Parse(Console.ReadLine());Rectangle[] a = new Rectangle[m + 5];for (int i = 0 ; i < m ; i++) {string[] te = Console.ReadLine().Split();a[i].bian = int.Parse(te[0]);a[i].len = Math.Max(int.Parse(te[1]) , int.Parse(te[2]));a[i].wid = Math.Min(int.Parse(te[1]) , int.Parse(te[2]));}Array.Sort(a , 0 , m , new MyComparer());Console.WriteLine(a[0].bian + " " + a[0].len + " " + a[0].wid);for (int i = 1 ; i < m ; i++) {if (a[i].len == a[i - 1].len && a[i].wid == a[i - 1].wid && a[i].bian == a[i - 1].bian)continue;Console.WriteLine(a[i].bian + " " + a[i].len + " " + a[i].wid);}}}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1094 {class Program {static void Main(string[] args) {string[] sb = Console.ReadLine().Split();double r = double.Parse(sb[0]), h = double.Parse(sb[1]);double area = (2 * r * r + 2 * r * h) * Math.PI;Console.Write("Area=");Console.WriteLine(area.ToString("0.000"));}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1095 {class Program {static void Main(string[] args) {int n = int.Parse(Console.ReadLine());Console.WriteLine(n % 10 * 100 + n / 10 % 10 * 10 + n / 100);}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1096 {class Program {static void Main(string[] args) {string[] sb = Console.ReadLine().Split();Console.WriteLine("{0} {1}", sb[1], sb[0]);}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1097 {class Program {static void Main(string[] args) {string[] sb = Console.ReadLine().Split();int[] a = new int[3];a[0] = int.Parse(sb[0]); a[1] = int.Parse(sb[1]); a[2] = int.Parse(sb[2]);Array.Sort(a);Console.WriteLine("{0} {1} {2}", a[0], a[1], a[2]);}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1098 {class Program {static void Main(string[] args) {string[] sb = Console.ReadLine().Split();double x = double.Parse(sb[0]), y = double.Parse(sb[1]), z = double.Parse(sb[2]);Console.WriteLine(((x + y + z) / 3).ToString("0.000"));}}}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace AK1099 {class Program {static void Main(string[] args) {int f = int.Parse(Console.ReadLine());double c = 5.0 * (f - 32) / 9;Console.WriteLine(c.ToString("0.000"));}}}