buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
change_count
int64
0
100
using System; class Program { static void Main() { string s; while ((s = Console.ReadLine()) != null) { int w = int.Parse(s); for (int n = 1;; n *= 2) { if (w % (n * 2) != 0) { Console.Write(n); w -= n; if (w > 0) Console.Write(" "); else break; } } } } }
using System; class Program { static void Main() { string s; while ((s = Console.ReadLine()) != null) { int w = int.Parse(s); for (int n = 1;; n *= 2) { if (w % (n * 2) != 0) { Console.Write(n); w -= n; if (w > 0) Console.Write(" "); else break; } } Console.WriteLine(); } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
100
6
using System; namespace _0031 { class Program { static void Main(string[] args) { while (true) { string now = Console.ReadLine(); if (now == null) { break; } int x = int.Parse(now); string two = Convert.ToString((x), 2); int j = 1; int k = 0; for (int i = two.Length - 1; i >= 0; i--) { if (two[i] == '1') { if (k == 0) { Console.Write(j); } else { Console.Write(" " + j); } k++; } j = j * 2; } } } } }
using System; namespace _0031 { class Program { static void Main(string[] args) { while (true) { string now = Console.ReadLine(); if (now == null) { break; } int x = int.Parse(now); string two = Convert.ToString((x), 2); int j = 1; int k = 0; for (int i = two.Length - 1; i >= 0; i--) { if (two[i] == '1') { if (k == 0) { Console.Write(j); } else { Console.Write(" " + j); } k++; } j = j * 2; } Console.WriteLine(); } } } }
[["+", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["+", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
152
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } int myP = 0, eneP = 0; for (int i = 0; i < n; i++) { int[] scores = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (scores[0] > scores[1]) { myP += (scores[0] + scores[1]); } else if (scores[0] == scores[1]) { eneP += (scores[0] + scores[1]); } else { myP += scores[0]; eneP += scores[1]; } } Console.WriteLine(myP + " " + eneP); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } int myP = 0, eneP = 0; for (int i = 0; i < n; i++) { int[] scores = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); if (scores[0] > scores[1]) { myP += (scores[0] + scores[1]); } else if (scores[0] < scores[1]) { eneP += (scores[0] + scores[1]); } else { myP += scores[0]; eneP += scores[1]; } } Console.WriteLine(myP + " " + eneP); } } } }
[["-", 8, 196, 0, 57, 75, 57, 15, 16, 17, 60], ["+", 8, 196, 0, 57, 75, 57, 15, 16, 17, 18]]
8
220
2
using System; using System.Text; using System.Linq; class aizu_judge { static void Main() { while (true) { int aPoint = 0, bPoint = 0; int n = Convert.ToInt32(Console.ReadLine()); if (n == 0) break; for (int i = 0; i < n; i++) { int[] card = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (card[0] > card[1]) aPoint += card[0] + card[1]; else if (card[0] < card[1]) bPoint += card[0] + card[1]; else aPoint += card[0]; bPoint += card[1]; } Console.WriteLine("{0} {1}", aPoint, bPoint); } } }
using System; using System.Text; using System.Linq; class aizu_judge { static void Main() { while (true) { int aPoint = 0, bPoint = 0; int n = Convert.ToInt32(Console.ReadLine()); if (n == 0) break; for (int i = 0; i < n; i++) { int[] card = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (card[0] > card[1]) aPoint += card[0] + card[1]; else if (card[0] < card[1]) bPoint += card[0] + card[1]; else { aPoint += card[0]; bPoint += card[1]; } } Console.WriteLine("{0} {1}", aPoint, bPoint); } } }
[["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 45], ["+", 8, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
8
180
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { // 0 // 1[2]3 4 // 5 public static int[] dice = new int[6]; public static void left() { int[] dice2 = new int[6]; dice2[0] = dice[3]; dice2[1] = dice[0]; dice2[2] = dice[2]; dice2[3] = dice[5]; dice2[4] = dice[4]; dice2[5] = dice[1]; dice = dice2; } public static void right() { int[] dice2 = new int[6]; dice2[0] = dice[1]; dice2[1] = dice[5]; dice2[2] = dice[2]; dice2[3] = dice[0]; dice2[4] = dice[4]; dice2[5] = dice[3]; dice = dice2; } public static void south() { int[] dice2 = new int[6]; dice2[0] = dice[4]; dice2[1] = dice[1]; dice2[2] = dice[0]; dice2[3] = dice[3]; dice2[4] = dice[5]; dice2[5] = dice[2]; dice = dice2; } public static void north() { int[] dice2 = new int[6]; dice2[0] = dice[2]; dice2[1] = dice[1]; dice2[2] = dice[5]; dice2[3] = dice[3]; dice2[4] = dice[0]; dice2[5] = dice[4]; dice = dice2; } public static void east() { int[] dice2 = new int[6]; dice2[0] = dice[0]; dice2[1] = dice[4]; dice2[2] = dice[1]; dice2[3] = dice[2]; dice2[4] = dice[3]; dice2[5] = dice[4]; dice = dice2; } public static void west() { int[] dice2 = new int[6]; dice2[0] = dice[0]; dice2[1] = dice[2]; dice2[2] = dice[3]; dice2[3] = dice[4]; dice2[4] = dice[1]; dice2[5] = dice[4]; dice = dice2; } public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } dice[0] = 5; dice[1] = 4; dice[2] = 1; dice[3] = 3; dice[4] = 6; dice[5] = 2; int sum = 0; for (int i = 0; i < n; i++) { string str = Console.ReadLine(); if (str.Equals("North")) { north(); } if (str.Equals("East")) { east(); } if (str.Equals("West")) { west(); } if (str.Equals("South")) { south(); } if (str.Equals("Right")) { right(); } if (str.Equals("Left")) { left(); } sum += dice[2]; } Console.WriteLine(sum); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { // 0 // 1[2]3 4 // 5 public static int[] dice = new int[6]; public static void left() { int[] dice2 = new int[6]; dice2[0] = dice[3]; dice2[1] = dice[0]; dice2[2] = dice[2]; dice2[3] = dice[5]; dice2[4] = dice[4]; dice2[5] = dice[1]; dice = dice2; } public static void right() { int[] dice2 = new int[6]; dice2[0] = dice[1]; dice2[1] = dice[5]; dice2[2] = dice[2]; dice2[3] = dice[0]; dice2[4] = dice[4]; dice2[5] = dice[3]; dice = dice2; } public static void south() { int[] dice2 = new int[6]; dice2[0] = dice[4]; dice2[1] = dice[1]; dice2[2] = dice[0]; dice2[3] = dice[3]; dice2[4] = dice[5]; dice2[5] = dice[2]; dice = dice2; } public static void north() { int[] dice2 = new int[6]; dice2[0] = dice[2]; dice2[1] = dice[1]; dice2[2] = dice[5]; dice2[3] = dice[3]; dice2[4] = dice[0]; dice2[5] = dice[4]; dice = dice2; } public static void east() { int[] dice2 = new int[6]; dice2[0] = dice[0]; dice2[1] = dice[4]; dice2[2] = dice[1]; dice2[3] = dice[2]; dice2[4] = dice[3]; dice2[5] = dice[5]; dice = dice2; } public static void west() { int[] dice2 = new int[6]; dice2[0] = dice[0]; dice2[1] = dice[2]; dice2[2] = dice[3]; dice2[3] = dice[4]; dice2[4] = dice[1]; dice2[5] = dice[5]; dice = dice2; } public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } dice[0] = 5; dice[1] = 4; dice[2] = 1; dice[3] = 3; dice[4] = 6; dice[5] = 2; int sum = 1; for (int i = 0; i < n; i++) { string str = Console.ReadLine(); if (str.Equals("North")) { north(); } if (str.Equals("East")) { east(); } if (str.Equals("West")) { west(); } if (str.Equals("South")) { south(); } if (str.Equals("Right")) { right(); } if (str.Equals("Left")) { left(); } // Console.WriteLine(dice[2]); sum += dice[2]; } Console.WriteLine(sum); } } } }
[["-", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 11, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203]]
8
781
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int[] ints = line.Split(' ').Select(int.Parse).ToArray(); int n = ints[0]; int m = ints[1]; if (n == 0) { break; } int[] anke = new int[m]; for (int i = 0; i < n; i++) { ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (int j = 0; j < m; j++) { anke[j] += ints[j]; } } int cnt = 0; while (cnt != m) { int maxAnk = -1; int maxInd = -1; for (int i = 0; i < m; i++) { if (maxAnk < anke[i]) { maxAnk = anke[i]; maxInd = i; } } anke[maxInd] = -1; Console.Write(maxInd); if (cnt != m - 1) { Console.Write(" "); } cnt++; } Console.WriteLine(); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int[] ints = line.Split(' ').Select(int.Parse).ToArray(); int n = ints[0]; int m = ints[1]; if (n == 0) { break; } int[] anke = new int[m]; for (int i = 0; i < n; i++) { ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); for (int j = 0; j < m; j++) { anke[j] += ints[j]; } } int cnt = 0; while (cnt != m) { int maxAnk = -1; int maxInd = -1; for (int i = 0; i < m; i++) { if (maxAnk < anke[i]) { maxAnk = anke[i]; maxInd = i; } } anke[maxInd] = -1; Console.Write(maxInd + 1); if (cnt != m - 1) { Console.Write(" "); } cnt++; } Console.WriteLine(); } } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
295
2
using System; class A { static void Main() { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } string a = Console.ReadLine(); for (int i = 0; i < n; i++) { string UI = ""; int j = 0; int continuing = 1; for (j = 1; j < a.Length; j++) { if (a[j - 1] == a[j]) { continuing++; } else { UI += continuing.ToString() + a[j - 1]; continuing = 1; } } UI += continuing.ToString() + a[j - 1]; a = UI; } Console.WriteLine(a); Console.ReadLine(); } } }
using System; class A { static void Main() { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } string a = Console.ReadLine(); for (int i = 0; i < n; i++) { string UI = ""; int j = 0; int continuing = 1; for (j = 1; j < a.Length; j++) { if (a[j - 1] == a[j]) { continuing++; } else { UI += continuing.ToString() + a[j - 1]; continuing = 1; } } UI += continuing.ToString() + a[j - 1]; a = UI; } Console.WriteLine(a); } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
175
6
using System; public class p0511 { p0511() { string str; bool[] a = new bool[31]; while ((str = Console.ReadLine()) != null) { for (int i = 0; i < 31; ++i) a[i] = true; a[int.Parse(str)] = false; for (int i = 0; i < 27; ++i) a[int.Parse(Console.ReadLine())] = false; for (int i = 0; i < 31; ++i) if (a[i]) Console.WriteLine("{0}", i); } } public static int Main(string[] args) { new p0511(); return 0; } }
using System; public class p0511 { p0511() { string str; bool[] a = new bool[31]; while ((str = Console.ReadLine()) != null) { for (int i = 0; i < 31; ++i) a[i] = true; a[int.Parse(str)] = false; for (int i = 0; i < 27; ++i) a[int.Parse(Console.ReadLine())] = false; for (int i = 1; i < 31; ++i) if (a[i]) Console.WriteLine("{0}", i); } } public static int Main(string[] args) { new p0511(); return 0; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
158
2
using System; using System.Linq; namespace AOJ2 { class Program { static void Main() { Console.WriteLine(string.Join( "", Console.ReadLine() .Select(x => Convert.ToChar(x >= 'X' ? x - 23 : x + 3).ToString()) .ToArray())); } } }
using System; using System.Linq; namespace AOJ2 { class Program { static void Main() { Console.WriteLine(string.Join( "", Console.ReadLine() .Select(x => Convert.ToChar(x <= 'C' ? x + 23 : x - 3).ToString()) .ToArray())); } } }
[["-", 3, 4, 0, 28, 0, 41, 15, 16, 17, 20], ["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 19], ["-", 0, 28, 0, 41, 15, 16, 12, 252, 0, 253], ["+", 0, 28, 0, 41, 15, 16, 12, 252, 0, 253], ["-", 3, 4, 0, 28, 0, 41, 64, 16, 17, 33], ["+", 3, 4, 0, 28, 0, 41, 64, 16, 17, 72], ["-", 3, 4, 0, 28, 0, 41, 75, 16, 17, 72], ["+", 3, 4, 0, 28, 0, 41, 75, 16, 17, 33]]
8
74
8
using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Text; namespace AOJ { class Program { static void Main(string[] args) { while (true) { var nk = Console.ReadLine().Split(' '); int n = int.Parse(nk[0]), k = int.Parse(nk[1]); if (n == 0 && k == 0) break; var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } int sum = 0, r = 0; for (int i = 0; i < n; i++) { if (i < k) { sum += a[i]; } else { sum -= a[i - k]; sum += a[i]; } r = Math.Max(r, sum); } Console.WriteLine(r); } } } }
using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; using System.Text; namespace AOJ { class Program { static void Main(string[] args) { while (true) { var nk = Console.ReadLine().Split(' '); int n = int.Parse(nk[0]), k = int.Parse(nk[1]); if (n == 0 && k == 0) break; var a = new int[n]; for (int i = 0; i < n; i++) { a[i] = int.Parse(Console.ReadLine()); } int sum = 0, r = 0; for (int i = 0; i < n; i++) { if (i < k) { sum += a[i]; } else { sum -= a[i - k]; sum += a[i]; r = Math.Max(r, sum); } } Console.WriteLine(r); } } } }
[["-", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46], ["+", 0, 7, 8, 196, 0, 57, 75, 196, 0, 46]]
8
228
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int jcnt = 0, icnt = 0; for (int i = 0; i < line.Length - 2; i++) { if (line[i] == 'J') { if (line[i + 1] == 'O' && line[i + 2] == 'I') { jcnt++; } } if (line[i] == 'I') { if (line[i + 1] == 'O' && line[i + 2] == 'I') { icnt++; } } } Console.WriteLine(jcnt); Console.WriteLine(icnt); break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int jcnt = 0, icnt = 0; for (int i = 0; i < line.Length - 2; i++) { if (line[i] == 'J') { if (line[i + 1] == 'O' && line[i + 2] == 'I') { jcnt++; } } if (line[i] == 'I') { if (line[i + 1] == 'O' && line[i + 2] == 'I') { icnt++; } } } Console.WriteLine(jcnt); Console.WriteLine(icnt); // break; } } } }
[["-", 8, 196, 0, 52, 8, 196, 0, 93, 0, 94], ["-", 8, 196, 0, 52, 8, 196, 0, 93, 0, 35]]
8
195
2
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace AOJ2 { class Program { static void Main() { var param = int.Parse(Console.ReadLine()); while (param != 0) { var taroCard = Read(param).OrderBy(x => x).ToList(); var hanakoCard = Enumerable.Range(1, param * 2) .Except(taroCard) .OrderBy(x => x) .ToList(); var filedCard = 0; while (hanakoCard.Count != 0) { var kouho = taroCard.Where(x => filedCard < x).FirstOrDefault(); filedCard = kouho; taroCard.Remove(kouho); if (taroCard.Count != 0) break; kouho = hanakoCard.Where(x => filedCard < x).FirstOrDefault(); filedCard = kouho; hanakoCard.Remove(kouho); } Console.WriteLine(hanakoCard.Count); Console.WriteLine(taroCard.Count); param = int.Parse(Console.ReadLine()); } } private static IEnumerable<int> Read(int loop) { for (int i = 0; i < loop; i++) { yield return int.Parse(Console.ReadLine()); } } } }
using System; using System.Linq; using System.Collections.Generic; using System.Text; namespace AOJ2 { class Program { static void Main() { var param = int.Parse(Console.ReadLine()); while (param != 0) { var taroCard = Read(param).OrderBy(x => x).ToList(); var hanakoCard = Enumerable.Range(1, param * 2) .Except(taroCard) .OrderBy(x => x) .ToList(); var filedCard = 0; while (hanakoCard.Count != 0) { var kouho = taroCard.Where(x => filedCard < x).FirstOrDefault(); filedCard = kouho; taroCard.Remove(kouho); if (taroCard.Count == 0) break; kouho = hanakoCard.Where(x => filedCard < x).FirstOrDefault(); filedCard = kouho; hanakoCard.Remove(kouho); } Console.WriteLine(hanakoCard.Count); Console.WriteLine(taroCard.Count); param = int.Parse(Console.ReadLine()); } } private static IEnumerable<int> Read(int loop) { for (int i = 0; i < loop; i++) { yield return int.Parse(Console.ReadLine()); } } } }
[["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 52, 8, 196, 0, 57, 15, 16, 17, 60]]
8
261
2
using System; using System.Collections.Generic; using System.Linq; namespace _527_SettingGoStones { class Program { static void Main(string[] args) { while (true) { // input int stoneAllCount = int.Parse(Console.ReadLine()); if (stoneAllCount == 0) { break; } int[] stoneState = new int[stoneAllCount]; for (int lp = 0; lp < stoneAllCount; lp++) { stoneState[lp] = int.Parse(Console.ReadLine()); } // process List<Stones> list = new List<Stones>(stoneState.Length); for (int lp = 0; lp < stoneState.Length; lp++) { bool isOdd = (lp + 1) % 2 == 1; //?\???°?????´??? if (isOdd) { //?????????????????? list = Stones.Put(list, new Stones(stoneState[lp], 1)); } //??¶??°?????´??? else { int rightIndex = list.Count - 1; int sideColor = list[rightIndex].Color; //????????¨??????????????´??? if (stoneState[lp] == sideColor) { //?????????????????? list = Stones.Put(list, new Stones(stoneState[lp], 1)); } //????????´??? else { //???????????????????????????????????????????????§????????????????????????????????????????????? int mixIndex = list.Count - 1; list[mixIndex].Convert(); list[mixIndex].AddCount(1); //??±??? //??????????´????????????° if (0 < mixIndex) { list[mixIndex - 1].AddCount(list[mixIndex].Count); list.RemoveAt(mixIndex); } } } } // output int whiteCount = list.Where(item => item.Color == Stones.White) .Sum(item => item.Count); Console.WriteLine(whiteCount); } } } } class Stones { public Stones(int color, int count) { this.Color = color; this.Count = count; } public int Color { set; get; } public int Count { set; get; } public static int White = 0; public static int Black = 1; public void Convert() { if (Color == White) Color = Black; else Color = White; } public void AddCount(int count) { Count += count; } public static List<Stones> Put(List<Stones> list, Stones item) { if (1 < list.Count) { int rightIndex = list.Count - 1; int sideColor = list[rightIndex].Color; //???????????????????¢??????????????????????????????°??±??? if (item.Color == sideColor) { list[rightIndex].AddCount(item.Count); } //????????´????????°?????????????????????????????\?????? else { list.Add(item); } } else { list.Add(item); } return list; } }
using System; using System.Collections.Generic; using System.Linq; namespace _527_SettingGoStones { class Program { static void Main(string[] args) { while (true) { // input int stoneAllCount = int.Parse(Console.ReadLine()); if (stoneAllCount == 0) { break; } int[] stoneState = new int[stoneAllCount]; for (int lp = 0; lp < stoneAllCount; lp++) { stoneState[lp] = int.Parse(Console.ReadLine()); } // process List<Stones> list = new List<Stones>(stoneState.Length); for (int lp = 0; lp < stoneState.Length; lp++) { bool isOdd = (lp + 1) % 2 == 1; //?\???°?????´??? if (isOdd) { //?????????????????? list = Stones.Put(list, new Stones(stoneState[lp], 1)); } //??¶??°?????´??? else { int rightIndex = list.Count - 1; int sideColor = list[rightIndex].Color; //????????¨??????????????´??? if (stoneState[lp] == sideColor) { //?????????????????? list = Stones.Put(list, new Stones(stoneState[lp], 1)); } //????????´??? else { //???????????????????????????????????????????????§????????????????????????????????????????????? int mixIndex = list.Count - 1; list[mixIndex].Convert(); list[mixIndex].AddCount(1); //??±??? //??????????´????????????° if (0 < mixIndex) { list[mixIndex - 1].AddCount(list[mixIndex].Count); list.RemoveAt(mixIndex); } } } } // output int whiteCount = list.Where(item => item.Color == Stones.White) .Sum(item => item.Count); Console.WriteLine(whiteCount); } } } } class Stones { public Stones(int color, int count) { this.Color = color; this.Count = count; } public int Color { set; get; } public int Count { set; get; } public static int White = 0; public static int Black = 1; public void Convert() { if (Color == White) Color = Black; else Color = White; } public void AddCount(int count) { Count += count; } public static List<Stones> Put(List<Stones> list, Stones item) { if (0 < list.Count) { int rightIndex = list.Count - 1; int sideColor = list[rightIndex].Color; //???????????????????¢??????????????????????????????°??±??? if (item.Color == sideColor) { list[rightIndex].AddCount(item.Count); } //????????´????????°?????????????????????????????\?????? else { list.Add(item); } } else { list.Add(item); } return list; } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 31, 203]]
8
532
2
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; class Program { static void Main() { var sc = new Scanner(); int K = sc.IntArray(10).OrderBy(x => x).Take(3).Sum(); int W = sc.IntArray(10).OrderBy(x => x).Take(3).Sum(); Console.WriteLine(K + " " + W); Console.ReadKey(); } } static class Extensions { public static IEnumerable<T> Output<T>(this IEnumerable<T> source) { foreach (var item in source) { Console.WriteLine(item); } return source; } public static T Print<T>(this T obj) { Console.WriteLine(obj); return obj; } } public class Scanner { string[] buffer = new string[0]; int index = 0; public char[] SplitChars { get; set; } public string String() { if (index < buffer.Length) return buffer[index++]; string line = ""; while (line == "") line = Console.ReadLine(); if (line == null) return null; buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); index = 0; return buffer[index++]; } public string[] StringArray(int count) { return NextArray(count, x => x); } public void Skip(int count) { for (int i = 0; i < count; i++) String(); } public T Next<T>(Func<string, T> parser) { return parser(String()); } public T[] NextArray<T>(int count, Func<string, T> parser) { var arr = new T[count]; for (int i = 0; i < count; i++) arr[i] = Next(parser); return arr; } public int Int() { return Next(int.Parse); } public int[] IntArray(int count) { return NextArray(count, int.Parse); } public double Double() { return Next(double.Parse); } public double[] DoubleArray(int count) { return NextArray(count, double.Parse); } }
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; class Program { static void Main() { var sc = new Scanner(); int K = sc.IntArray(10).OrderByDescending(x => x).Take(3).Sum(); int W = sc.IntArray(10).OrderByDescending(x => x).Take(3).Sum(); Console.WriteLine(K + " " + W); Console.ReadKey(); } } static class Extensions { public static IEnumerable<T> Output<T>(this IEnumerable<T> source) { foreach (var item in source) { Console.WriteLine(item); } return source; } public static T Print<T>(this T obj) { Console.WriteLine(obj); return obj; } } public class Scanner { string[] buffer = new string[0]; int index = 0; public char[] SplitChars { get; set; } public string String() { if (index < buffer.Length) return buffer[index++]; string line = ""; while (line == "") line = Console.ReadLine(); if (line == null) return null; buffer = line.Split(SplitChars, StringSplitOptions.RemoveEmptyEntries); index = 0; return buffer[index++]; } public string[] StringArray(int count) { return NextArray(count, x => x); } public void Skip(int count) { for (int i = 0; i < count; i++) String(); } public T Next<T>(Func<string, T> parser) { return parser(String()); } public T[] NextArray<T>(int count, Func<string, T> parser) { var arr = new T[count]; for (int i = 0; i < count; i++) arr[i] = Next(parser); return arr; } public int Int() { return Next(int.Parse); } public int[] IntArray(int count) { return NextArray(count, int.Parse); } public double Double() { return Next(double.Parse); } public double[] DoubleArray(int count) { return NextArray(count, double.Parse); } }
[["-", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["+", 205, 213, 63, 214, 205, 213, 63, 214, 141, 22]]
8
494
4
using System; using System.Linq; namespace _0535 { class Program { static bool[,] ice; static int ret = 0; static void bfs(int x, int y, int count) { ice[x, y] = false; count++; ret = Math.Max(ret, count); if (ice[x - 1, y]) bfs(x - 1, y, count); if (ice[x + 1, y]) bfs(x + 1, y, count); if (ice[x, y - 1]) bfs(x, y - 1, count); if (ice[x, y + 1]) bfs(x, y + 1, count); ice[x, y] = true; } static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); int m = int.Parse(Console.ReadLine()); if (n == 0 && m == 0) break; ice = new bool[m + 2, n + 2]; for (int i = 0; i < m; i++) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int j = 0; j < n; j++) { ice[i + 1, j + 1] = x[j] == 1; } } for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (ice[i + 1, j + 1]) bfs(i + 1, j + 1, 0); } } Console.WriteLine(ret); } } } }
using System; using System.Linq; namespace _0535 { class Program { static bool[,] ice; static int ret = 0; static void bfs(int x, int y, int count) { ice[x, y] = false; count++; ret = Math.Max(ret, count); if (ice[x - 1, y]) bfs(x - 1, y, count); if (ice[x + 1, y]) bfs(x + 1, y, count); if (ice[x, y - 1]) bfs(x, y - 1, count); if (ice[x, y + 1]) bfs(x, y + 1, count); ice[x, y] = true; } static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); int m = int.Parse(Console.ReadLine()); if (n == 0 && m == 0) break; ret = 0; ice = new bool[m + 2, n + 2]; for (int i = 0; i < m; i++) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); for (int j = 0; j < n; j++) { ice[i + 1, j + 1] = x[j] == 1; } } for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { if (ice[i + 1, j + 1]) bfs(i + 1, j + 1, 0); } } Console.WriteLine(ret); } } } }
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
376
4
using System; public class Hello { public static int MAXC = 0; public static int[] dx = new int[] { 0, 1, 0, -1 }; public static int[] dy = new int[] { 1, 0, -1, 0 }; public static void Main() { while (true) { var w = int.Parse(Console.ReadLine().Trim()); var h = int.Parse(Console.ReadLine().Trim()); if (w == 0 && h == 0) break; var map = new int[h, w]; for (int i = 0; i < h; i++) { string[] line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < w; j++) map[i, j] = int.Parse(line[j]); } for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (map[i, j] == 1) goDfs(map, i, j, 1, h, w); Console.WriteLine(MAXC); } } public static void goDfs(int[,] map, int x, int y, int via, int h, int w) { MAXC = Math.Max(MAXC, via); map[x, y] = 0; for (int i = 0; i < 4; i++) { var nx = x + dx[i]; var ny = y + dy[i]; if (nx >= 0 && nx < h && ny >= 0 && ny < w && map[nx, ny] == 1) goDfs(map, nx, ny, via + 1, h, w); } map[x, y] = 1; } }
using System; public class Hello { public static int MAXC = 0; public static int[] dx = new int[] { 0, 1, 0, -1 }; public static int[] dy = new int[] { 1, 0, -1, 0 }; public static void Main() { while (true) { MAXC = 0; var w = int.Parse(Console.ReadLine().Trim()); var h = int.Parse(Console.ReadLine().Trim()); if (w == 0 && h == 0) break; var map = new int[h, w]; for (int i = 0; i < h; i++) { string[] line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < w; j++) map[i, j] = int.Parse(line[j]); } for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (map[i, j] == 1) goDfs(map, i, j, 1, h, w); Console.WriteLine(MAXC); } } public static void goDfs(int[,] map, int x, int y, int via, int h, int w) { MAXC = Math.Max(MAXC, via); map[x, y] = 0; for (int i = 0; i < 4; i++) { var nx = x + dx[i]; var ny = y + dy[i]; if (nx >= 0 && nx < h && ny >= 0 && ny < w && map[nx, ny] == 1) goDfs(map, nx, ny, via + 1, h, w); } map[x, y] = 1; } }
[["+", 0, 52, 8, 196, 0, 1, 0, 11, 31, 22], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 52, 8, 196, 0, 1, 0, 11, 12, 203], ["+", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
399
4
using System; using System.Collections; using System.Collections.Generic; class TEST { static void Main() { while (true) { var n = int.Parse(Console.ReadLine()); if (n == 0) break; Sol mySol = new Sol(n); mySol.Solve(); } } } class Sol { public void Solve() { List<Pair> L = new List<Pair>(); for (int i = 0; i < N; i++) { var d = ria(); L.Add(new Pair(d[0], d[1])); } L.Sort((x, y) => x.T > y.T ? 1 : x.T < y.T ? -1 : 0); bool chk = true; int sum = 0; for (int i = 0; i < N; i++) { sum += L[i].T; if (sum > L[i].W) { chk = false; break; } } Console.WriteLine(chk ? "Yes" : "No"); } int N; public Sol(int n_) { N = n_; } class Pair { public int T; public int W; public Pair(int t, int w) { T = t; W = w; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa() { return Console.ReadLine().Split(' '); } static int[] ria() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => int.Parse(e)); } static long[] rla() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => long.Parse(e)); } static double[] rda() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => double.Parse(e)); } }
using System; using System.Collections; using System.Collections.Generic; class TEST { static void Main() { while (true) { var n = int.Parse(Console.ReadLine()); if (n == 0) break; Sol mySol = new Sol(n); mySol.Solve(); } } } class Sol { public void Solve() { List<Pair> L = new List<Pair>(); for (int i = 0; i < N; i++) { var d = ria(); L.Add(new Pair(d[0], d[1])); } L.Sort((x, y) => x.W > y.W ? 1 : x.W < y.W ? -1 : 0); bool chk = true; int sum = 0; for (int i = 0; i < N; i++) { sum += L[i].T; if (sum > L[i].W) { chk = false; break; } } Console.WriteLine(chk ? "Yes" : "No"); } int N; public Sol(int n_) { N = n_; } class Pair { public int T; public int W; public Pair(int t, int w) { T = t; W = w; } } static String rs() { return Console.ReadLine(); } static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static String[] rsa() { return Console.ReadLine().Split(' '); } static int[] ria() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => int.Parse(e)); } static long[] rla() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => long.Parse(e)); } static double[] rda() { return Array.ConvertAll(Console.ReadLine().Split(' '), e => double.Parse(e)); } }
[["-", 0, 218, 8, 41, 15, 16, 31, 214, 141, 22], ["+", 0, 218, 8, 41, 15, 16, 31, 214, 141, 22], ["-", 0, 218, 8, 41, 15, 16, 12, 214, 141, 22], ["+", 0, 218, 8, 41, 15, 16, 12, 214, 141, 22], ["-", 8, 41, 75, 41, 15, 16, 31, 214, 141, 22], ["+", 8, 41, 75, 41, 15, 16, 31, 214, 141, 22], ["-", 8, 41, 75, 41, 15, 16, 12, 214, 141, 22], ["+", 8, 41, 75, 41, 15, 16, 12, 214, 141, 22]]
8
490
8
using System; public class Hello { public static void Main() { var p = new string[] { "lunch", "dinner", "midnight" }; while (true) { var n = int.Parse(Console.ReadLine().Trim()); if (n == 0) break; var a = new int[3]; var b = new int[3]; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' ', ':'); var h = int.Parse(line[0]); var m = int.Parse(line[1]); var m2 = int.Parse(line[2]); var t1 = 60 * h + m; if (t1 >= 660 && t1 <= 899) b[0]++; else if (t1 >= 1080 && t1 <= 1259) b[1]++; else if (t1 >= 1260 && t1 <= 1439) b[2]++; else if (t1 >= 0 && t1 <= 119) b[2]++; var t2 = m2 - m; if (t2 < 0) t2 += 60; bool ok; ok = t2 <= 8 ? true : false; if (t1 >= 660 && t1 <= 899 && ok) a[0]++; else if (t1 >= 1080 && t1 <= 1259 && ok) a[1]++; else if (t1 >= 1260 && t1 <= 1439 && ok) a[2]++; else if (t1 >= 0 && t1 <= 119 && ok) a[2]++; } for (int j = 0; j < 3; j++) { if (a[j] == 0) Console.WriteLine("{0} no guest", p[j]); else Console.WriteLine("{0} {1}", p[j], a[j] * 100 / b[j]); } } } }
using System; public class Hello { public static void Main() { var p = new string[] { "lunch", "dinner", "midnight" }; while (true) { var n = int.Parse(Console.ReadLine().Trim()); if (n == 0) break; var a = new int[3]; var b = new int[3]; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' ', ':'); var h = int.Parse(line[0]); var m = int.Parse(line[1]); var m2 = int.Parse(line[2]); var t1 = 60 * h + m; if (t1 >= 660 && t1 <= 899) b[0]++; else if (t1 >= 1080 && t1 <= 1259) b[1]++; else if (t1 >= 1260 && t1 <= 1439) b[2]++; else if (t1 >= 0 && t1 <= 119) b[2]++; var t2 = m2 - m; if (t2 < 0) t2 += 60; bool ok; ok = t2 <= 8 ? true : false; if (t1 >= 660 && t1 <= 899 && ok) a[0]++; else if (t1 >= 1080 && t1 <= 1259 && ok) a[1]++; else if (t1 >= 1260 && t1 <= 1439 && ok) a[2]++; else if (t1 >= 0 && t1 <= 119 && ok) a[2]++; } for (int j = 0; j < 3; j++) { if (b[j] == 0) Console.WriteLine("{0} no guest", p[j]); else Console.WriteLine("{0} {1}", p[j], a[j] * 100 / b[j]); } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22], ["+", 8, 196, 0, 57, 15, 16, 31, 204, 205, 22]]
8
415
2
using System; public class hello { public static void Main() { var dx = new int[] { 0, -1, 0, 1 }; var dy = new int[] { 1, 0, -1, 0 }; while (true) { string[] line = Console.ReadLine().Trim().Split(' '); var w = int.Parse(line[0]); var h = int.Parse(line[1]); if (w == 0 && h == 0) break; var x = 0; var y = 0; var d = 3; while (true) { line = Console.ReadLine().Trim().Split(' '); var c = line[0]; if (c == "STOP") { Console.WriteLine("{0} {1}", y + 1, x + 1); break; } else if (c == "LEFT") { d--; if (d == -1) d = 3; } else if (c == "RIGHT") { d++; if (d == 4) d = 0; } else if (c == "FORWARD") { var c2 = int.Parse(line[1]); var nx = x + c2 * dx[d]; var ny = y + c2 * dy[d]; if (nx < 0) nx = 0; if (nx >= h) nx = h - 1; if (ny < 0) ny = 0; if (ny >= w) ny = w; x = nx; y = ny; } else if (c == "BACKWARD") { var nd = d + 2; if (nd > 3) nd -= 4; var c2 = int.Parse(line[1]); var nx = x + c2 * dx[nd]; var ny = y + c2 * dy[nd]; if (nx < 0) nx = 0; if (nx >= h) nx = h - 1; if (ny < 0) ny = 0; if (ny >= w) ny = w; x = nx; y = ny; } } } } }
using System; public class hello { public static void Main() { var dx = new int[] { 0, -1, 0, 1 }; var dy = new int[] { 1, 0, -1, 0 }; while (true) { string[] line = Console.ReadLine().Trim().Split(' '); var w = int.Parse(line[0]); var h = int.Parse(line[1]); if (w == 0 && h == 0) break; var x = 0; var y = 0; var d = 3; while (true) { line = Console.ReadLine().Trim().Split(' '); var c = line[0]; if (c == "STOP") { Console.WriteLine("{0} {1}", y + 1, x + 1); break; } else if (c == "LEFT") { d--; if (d == -1) d = 3; } else if (c == "RIGHT") { d++; if (d == 4) d = 0; } else if (c == "FORWARD") { var c2 = int.Parse(line[1]); var nx = x + c2 * dx[d]; var ny = y + c2 * dy[d]; if (nx < 0) nx = 0; if (nx >= h) nx = h - 1; if (ny < 0) ny = 0; if (ny >= w) ny = w - 1; x = nx; y = ny; } else if (c == "BACKWARD") { var nd = d + 2; if (nd > 3) nd -= 4; var c2 = int.Parse(line[1]); var nx = x + c2 * dx[nd]; var ny = y + c2 * dy[nd]; if (nx < 0) nx = 0; if (nx >= h) nx = h - 1; if (ny < 0) ny = 0; if (ny >= w) ny = w - 1; x = nx; y = ny; } } } } }
[["+", 0, 57, 64, 1, 0, 11, 12, 16, 17, 33], ["+", 0, 57, 64, 1, 0, 11, 12, 16, 12, 203]]
8
457
4
using System.Linq; using System.Collections.Generic; using System; public class P { public int x1 { get; set; } public int x2 { get; set; } } public class hello { public static void Main() { while (true) { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var c = int.Parse(line[2]); if (a == 0 && b == 0 && c == 0) break; getAns(a, b, c); } } static void getAns(int a, int b, int c) { var ok = false; var ps = new P[2]; if (c == 0) { ps[0] = new P { x1 = 1, x2 = 0 }; ps[1] = new P { x1 = a, x2 = b }; ok = true; goto exit; } var ta = getDiv(a); var tc = getDiv2(c); foreach (var x in ta) foreach (var y in tc) { var p = x.x1; var r = x.x2; var q = y.x1; var s = y.x2; if (p * s + q * r == b) { ps[0] = new P { x1 = p, x2 = q }; ps[1] = new P { x1 = r, x2 = s }; ok = true; goto exit; } if (p * q + s * r == b) { ps[0] = new P { x1 = p, x2 = s }; ps[1] = new P { x1 = r, x2 = q }; ok = true; goto exit; } } exit:; if (!ok) Console.WriteLine("Impossible"); else { var prt = ps.OrderByDescending(x => x.x1).ThenByDescending(x => x.x2).ToArray(); Console.WriteLine("{0} {1} {2} {3}", prt[0].x1, prt[0].x2, prt[1].x1, prt[1].x2); } } static List<P> getDiv2(int a) { var ap = a < 0 ? -a : a; var t = new List<P>(); for (int i = 1; i * i <= ap; i++) if (ap % i == 0) { var w = ap / i; if (i <= w) if (a > 0) { t.Add(new P { x1 = i, x2 = w }); t.Add(new P { x1 = -w, x2 = i }); } else { t.Add(new P { x1 = -i, x2 = w }); t.Add(new P { x1 = -w, x2 = i }); } } return t; } static List<P> getDiv(int a) { var t = new List<P>(); for (int i = 1; i * i <= a; i++) if (a % i == 0) { var w = a / i; if (i <= w) t.Add(new P { x1 = i, x2 = w }); } return t; } }
using System.Linq; using System.Collections.Generic; using System; public class P { public int x1 { get; set; } public int x2 { get; set; } } public class hello { public static void Main() { while (true) { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); var c = int.Parse(line[2]); if (a == 0 && b == 0 && c == 0) break; getAns(a, b, c); } } static void getAns(int a, int b, int c) { var ok = false; var ps = new P[2]; if (c == 0) { ps[0] = new P { x1 = 1, x2 = 0 }; ps[1] = new P { x1 = a, x2 = b }; ok = true; goto exit; } var ta = getDiv(a); var tc = getDiv2(c); foreach (var x in ta) foreach (var y in tc) { var p = x.x1; var r = x.x2; var q = y.x1; var s = y.x2; if (p * s + q * r == b) { ps[0] = new P { x1 = p, x2 = q }; ps[1] = new P { x1 = r, x2 = s }; ok = true; goto exit; } if (p * q + s * r == b) { ps[0] = new P { x1 = p, x2 = s }; ps[1] = new P { x1 = r, x2 = q }; ok = true; goto exit; } } exit:; if (!ok) Console.WriteLine("Impossible"); else { var prt = ps.OrderByDescending(x => x.x1).ThenByDescending(x => x.x2).ToArray(); Console.WriteLine("{0} {1} {2} {3}", prt[0].x1, prt[0].x2, prt[1].x1, prt[1].x2); } } static List<P> getDiv2(int a) { var ap = a < 0 ? -a : a; var t = new List<P>(); for (int i = 1; i * i <= ap; i++) if (ap % i == 0) { var w = ap / i; if (i <= w) if (a > 0) { t.Add(new P { x1 = i, x2 = w }); t.Add(new P { x1 = -w, x2 = -i }); } else { t.Add(new P { x1 = -i, x2 = w }); t.Add(new P { x1 = -w, x2 = i }); } } return t; } static List<P> getDiv(int a) { var t = new List<P>(); for (int i = 1; i * i <= a; i++) if (a % i == 0) { var w = a / i; if (i <= w) t.Add(new P { x1 = i, x2 = w }); } return t; } }
[["+", 0, 230, 10, 229, 0, 11, 12, 241, 0, 33]]
8
716
1
using System.Text; using System.Collections.Generic; using System; public class hello { public static Dictionary<string, int> d; public static Dictionary<int, string> dr; public static string[] z, z0, z1; public static void Main() { z = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts" }; z0 = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; z1 = new string[] { "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts" }; d = new Dictionary<string, int>(); dr = new Dictionary<int, string>(); var map = new int[38, 38]; for (int i = 0; i < 38; i++) { d[z[i]] = i; dr[i] = z[i]; } Array.Reverse(z0); Array.Reverse(z1); var maxv = new int[38]; var maxcs = new int[38]; var n = int.Parse(Console.ReadLine().Trim()); var p = 0; while (p++ < n) { string[] line = Console.ReadLine().Trim().Split(' '); foreach (var x in line) getAns(x, maxv, maxcs, map); } print(maxv, maxcs); } static void print(int[] maxv, int[] maxcs) { var sb = new StringBuilder(); for (int i = 0; i < 38; i++) { var cw = dr[maxcs[i]]; sb.Append(string.Format("{0} {1} {2}\n", dr[i], cw, maxv[i])); } Console.Write(sb); } static void getAns(string s, int[] maxv, int[] maxcs, int[,] map) { if (s.Length == 1) return; var p = 0; var pre = 0; var pret = s.Substring(0, 2); var find = false; foreach (var y in z1) if (pret == y) { find = true; pre = d[y]; p += 2; break; } if (p == s.Length) return; if (!find) { pre = s[0] - 'a'; p++; } while (true) { find = false; if (p == s.Length - 1) { goto next; } var t = s.Substring(p, 2); foreach (var y in z1) if (t == y) { find = true; var ti = d[y]; map[pre, ti]++; if (map[pre, ti] > maxv[pre]) { maxv[pre] = map[pre, ti]; maxcs[pre] = ti; } if (map[pre, ti] == maxv[pre] && ti > maxcs[pre]) maxcs[pre] = ti; p += 2; pre = ti; break; } next:; if (!find) { var ti = s[p] - 'a'; map[pre, ti]++; if (map[pre, ti] > maxv[pre]) { maxv[pre] = map[pre, ti]; maxcs[pre] = ti; } if (map[pre, ti] == maxv[pre] && ti > maxcs[pre]) maxcs[pre] = ti; pre = ti; p++; } if (p >= s.Length) break; } } }
using System.Text; using System.Collections.Generic; using System; public class hello { public static Dictionary<string, int> d; public static Dictionary<int, string> dr; public static string[] z, z0, z1; public static void Main() { z = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts" }; z0 = new string[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" }; z1 = new string[] { "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts" }; d = new Dictionary<string, int>(); dr = new Dictionary<int, string>(); var map = new int[38, 38]; for (int i = 0; i < 38; i++) { d[z[i]] = i; dr[i] = z[i]; } Array.Reverse(z0); Array.Reverse(z1); var maxv = new int[38]; var maxcs = new int[38]; var n = int.Parse(Console.ReadLine().Trim()); var p = 0; while (p++ < n) { string[] line = Console.ReadLine().Trim().Split(' '); foreach (var x in line) getAns(x, maxv, maxcs, map); } print(maxv, maxcs); } static void print(int[] maxv, int[] maxcs) { var sb = new StringBuilder(); for (int i = 0; i < 38; i++) { var cw = dr[maxcs[i]]; sb.Append(string.Format("{0} {1} {2}\n", dr[i], cw, maxv[i])); } Console.Write(sb); } static void getAns(string s, int[] maxv, int[] maxcs, int[,] map) { if (s.Length == 1) return; var p = 0; var pre = 0; var pret = s.Substring(0, 2); var find = false; foreach (var y in z1) if (pret == y) { find = true; pre = d[y]; p += 2; break; } if (p == s.Length) return; if (!find) { pre = s[0] - 'a'; p++; } while (true) { find = false; if (p == s.Length - 1) { goto next; } var t = s.Substring(p, 2); foreach (var y in z1) if (t == y) { find = true; var ti = d[y]; map[pre, ti]++; if (map[pre, ti] > maxv[pre]) { maxv[pre] = map[pre, ti]; maxcs[pre] = ti; } if (map[pre, ti] == maxv[pre] && ti < maxcs[pre]) maxcs[pre] = ti; p += 2; pre = ti; break; } next:; if (!find) { var ti = s[p] - 'a'; map[pre, ti]++; if (map[pre, ti] > maxv[pre]) { maxv[pre] = map[pre, ti]; maxcs[pre] = ti; } if (map[pre, ti] == maxv[pre] && ti < maxcs[pre]) maxcs[pre] = ti; pre = ti; p++; } if (p >= s.Length) break; } } }
[["-", 64, 196, 0, 57, 15, 16, 12, 16, 17, 47], ["+", 64, 196, 0, 57, 15, 16, 12, 16, 17, 18]]
8
1,034
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY<T> where T : IComparable { public T X, Y; public bool Flag = false; public PointXY(T _X, T _Y) { X = _X; Y = _Y; } public static bool operator ==(PointXY<T> P1, PointXY<T> P2) { return (P1.X.CompareTo(P2.X) == 0 && P1.Y.CompareTo(P2.Y) == 0); } public static bool operator !=(PointXY<T> P1, PointXY<T> P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY<T>)obj); } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == 0); } static int[] ReadLine72(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const int DefaultMax = 727272; static bool isPrime(int p) { if (p != 2 && p % 2 == 0) return false; if (p == 1) return false; int SQp = (int)(Math.Sqrt(p)); for (int i = 3; i <= SQp; i++) { if (p % i == 0) return false; } return true; } static void Main(string[] args) { while (true) { var adn = ReadLine72(); if (adn[0] == 0) return; int output = 0; for (int i = adn[0], n = 0; true; i += adn[1]) { if (isPrime(i)) { n++; } if (n == adn[2]) { Console.WriteLine(output); break; } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY<T> where T : IComparable { public T X, Y; public bool Flag = false; public PointXY(T _X, T _Y) { X = _X; Y = _Y; } public static bool operator ==(PointXY<T> P1, PointXY<T> P2) { return (P1.X.CompareTo(P2.X) == 0 && P1.Y.CompareTo(P2.Y) == 0); } public static bool operator !=(PointXY<T> P1, PointXY<T> P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY<T>)obj); } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == 0); } static int[] ReadLine72(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const int DefaultMax = 727272; static bool isPrime(int p) { if (p != 2 && p % 2 == 0) return false; if (p == 1) return false; int SQp = (int)(Math.Sqrt(p)); for (int i = 3; i <= SQp; i++) { if (p % i == 0) return false; } return true; } static void Main(string[] args) { while (true) { var adn = ReadLine72(); if (adn[0] == 0) return; for (int i = adn[0], n = 0; true; i += adn[1]) { if (isPrime(i)) { n++; } if (n == adn[2]) { Console.WriteLine(i); break; } } } } }
[["-", 0, 52, 8, 196, 0, 197, 0, 198, 39, 199], ["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 32], ["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 52, 8, 196, 0, 197, 0, 35], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
587
7
using System; using System.Linq; using System.Collections.Generic; namespace Test1 { class ClassMain { public static bool[] primes = Enumerable.Repeat(true, 1000000 + 1).ToArray(); public static void sieve() { primes[0] = false; primes[1] = false; for (int i = 2; i < primes.Length / 2 + 1; i++) { if (primes[i]) { for (int j = 2; j * i < primes.Length; j++) { primes[i * j] = false; } } } } public static void Main(String[] args) { sieve(); string line; while ((line = Console.ReadLine()) != null) { int[] ints = line.Split(' ').Select(int.Parse).ToArray(); int n = ints[0]; // int n = int.Parse(line); if (n == 0) { break; } // int m = ints[1]; int d = ints[1]; int ban = ints[2]; int cnt = 0; for (int i = 0;; i++) { if (primes[n + d * i]) { cnt++; } if (cnt == ban) { Console.WriteLine(n + d * 1); break; } } } } } }
using System; using System.Linq; using System.Collections.Generic; namespace Test1 { class ClassMain { public static bool[] primes = Enumerable.Repeat(true, 1000000 + 1).ToArray(); public static void sieve() { primes[0] = false; primes[1] = false; for (int i = 2; i < primes.Length / 2 + 1; i++) { if (primes[i]) { for (int j = 2; j * i < primes.Length; j++) { primes[i * j] = false; } } } } public static void Main(String[] args) { sieve(); string line; while ((line = Console.ReadLine()) != null) { int[] ints = line.Split(' ').Select(int.Parse).ToArray(); int n = ints[0]; // int n = int.Parse(line); if (n == 0) { break; } // int m = ints[1]; int d = ints[1]; int ban = ints[2]; int cnt = 0; for (int i = 0;; i++) { if (primes[n + d * i]) { cnt++; } if (cnt == ban) { Console.WriteLine(n + d * i); break; } } } } } }
[["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 22]]
8
278
2
using System; using System.Linq; namespace _1141 { class Program { static void Main(string[] args) { bool[] prime = new bool[1000010]; for (int i = 2; i < 1000010; i++) prime[i] = true; for (int i = 2; i < 1000010; i++) { if (prime[i]) { for (long j = i * i; 0 < j && j < 1000010; j += i) { prime[j] = false; } } } while (true) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x.Max() == 0) break; int find = 0; for (int i = x[0]; find < x[2]; i += x[1]) { if (prime[i]) { find++; if (find == x[2]) { Console.WriteLine(i); } } } } } } }
using System; using System.Linq; namespace _1141 { class Program { static void Main(string[] args) { bool[] prime = new bool[1000010]; for (int i = 2; i < 1000010; i++) prime[i] = true; for (int i = 2; i < Math.Sqrt(1000010); i++) { if (prime[i]) { for (long j = i * i; 0 < j && j < 1000010; j += i) { prime[j] = false; } } } while (true) { int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x.Max() == 0) break; int find = 0; for (int i = x[0]; find < x[2]; i += x[1]) { if (prime[i]) { find++; if (find == x[2]) { Console.WriteLine(i); } } } } } } }
[["+", 0, 7, 15, 16, 12, 213, 63, 214, 205, 22], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 0, 131], ["+", 0, 7, 15, 16, 12, 213, 63, 214, 141, 22], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 213, 3, 4, 0, 25]]
8
219
5
using System; class Program { static void Main(string[] args) { int Max, Min; while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) break; int[] numbers = new int[n]; for (int i = 0; i < n; i++) { numbers[i] = int.Parse(Console.ReadLine()); } Max = Min = numbers[0]; for (int i = 0; i < n; i++) { if (Max < numbers[i]) Max = numbers[i]; if (Min > numbers[i]) Min = numbers[i]; } int output = 0; for (int i = 0; i < n; i++) { output += numbers[i]; } output = (output - Min - Max) / n; Console.WriteLine(output); } } }
using System; class Program { static void Main(string[] args) { int Max, Min; while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) break; int[] numbers = new int[n]; for (int i = 0; i < n; i++) { numbers[i] = int.Parse(Console.ReadLine()); } Max = Min = numbers[0]; for (int i = 0; i < n; i++) { if (Max < numbers[i]) Max = numbers[i]; if (Min > numbers[i]) Min = numbers[i]; } int output = 0; for (int i = 0; i < n; i++) { output += numbers[i]; } output = (output - Min - Max) / (n - 2); Console.WriteLine(output); } } }
[["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 24], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 203], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
8
198
4
using System; namespace aoj1147 { class Program { static void Main(string[] args) { int n; do { n = int.Parse(Console.ReadLine()); int min = 1000, max = 0, sum = 0; int[] points = new int[n]; for (int i = 0; i < n; i++) { points[i] = int.Parse(Console.ReadLine()); if (points[i] < min) min = points[i]; if (max < points[i]) max = points[i]; } for (int i = 0; i < n; i++) { if (points[i] <= min) { min--; continue; } if (max <= points[i]) { max++; continue; } sum += points[i]; } Console.WriteLine(sum / (n - 2)); } while (n != 0); } } }
using System; namespace aoj1147 { class Program { static void Main(string[] args) { int n; do { n = int.Parse(Console.ReadLine()); int min = 1000, max = 0, sum = 0; int[] points = new int[n]; for (int i = 0; i < n; i++) { points[i] = int.Parse(Console.ReadLine()); if (points[i] < min) min = points[i]; if (max < points[i]) max = points[i]; } for (int i = 0; i < n; i++) { if (points[i] <= min) { min--; continue; } if (max <= points[i]) { max++; continue; } sum += points[i]; } if (n != 0) Console.WriteLine(sum / (n - 2)); } while (n != 0); } } }
[["+", 8, 196, 0, 82, 8, 196, 0, 57, 0, 121], ["+", 8, 196, 0, 82, 8, 196, 0, 57, 0, 24], ["+", 0, 82, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 82, 8, 196, 0, 57, 15, 16, 17, 79], ["+", 0, 82, 8, 196, 0, 57, 15, 16, 12, 203], ["+", 8, 196, 0, 82, 8, 196, 0, 57, 0, 25]]
8
204
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY<T> where T : IComparable { public T X, Y; public bool Flag = false; public PointXY(T _X, T _Y) { X = _X; Y = _Y; } public static bool operator ==(PointXY<T> P1, PointXY<T> P2) { return (P1.X.CompareTo(P2.X) == 0 && P1.Y.CompareTo(P2.Y) == 0); } public static bool operator !=(PointXY<T> P1, PointXY<T> P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY<T>)obj); } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == 0); } static int[] ReadLine72(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const int DefaultMax = 727272; static int w, h; static int[][] Map; static bool[][] Checked; static bool Check(int i, int j) { if (Map[i][j] == 0) { return false; } else if (Map[i][j] == 1 && Checked[i][j]) { return false; } else if (Map[i][j] == 1 && !Checked[i][j]) { Checked[i][j] = true; if (i > 0 && j > 0) { Check(i - 1, j - 1); } if (i > 0) { Check(i - 1, j); } if (i > 0 && j < w - 1) { Check(i - 1, j + 1); } if (j < w - 1) { Check(i, j + 1); } if (i < h - 1 && j > 0) { Check(i + 1, j - 1); } if (j > 0) { Check(i, j - 1); } if (i < h - 1 && j < w - 1) { Check(i + 1, j + 1); } if (i < h - 1) { Check(i + 1, j); } return true; } return false; } static void Main(string[] args) { while (true) { int output = 0; w = 0; h = 0; if (ReadLine_2(ref w, ref h)) return; Map = new int [h][]; Checked = new bool [h][]; for (int i = 0; i < h; i++) { Map[i] = ReadLine72(); Checked[i] = new bool[h]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (Check(i, j)) output++; } } Console.WriteLine(output); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY<T> where T : IComparable { public T X, Y; public bool Flag = false; public PointXY(T _X, T _Y) { X = _X; Y = _Y; } public static bool operator ==(PointXY<T> P1, PointXY<T> P2) { return (P1.X.CompareTo(P2.X) == 0 && P1.Y.CompareTo(P2.Y) == 0); } public static bool operator !=(PointXY<T> P1, PointXY<T> P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY<T>)obj); } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == 0); } static int[] ReadLine72(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const int DefaultMax = 727272; static int w, h; static int[][] Map; static bool[][] Checked; static bool Check(int i, int j) { if (Map[i][j] == 0) { return false; } else if (Map[i][j] == 1 && Checked[i][j]) { return false; } else if (Map[i][j] == 1 && !Checked[i][j]) { Checked[i][j] = true; if (i > 0 && j > 0) { Check(i - 1, j - 1); } if (i > 0) { Check(i - 1, j); } if (i > 0 && j < w - 1) { Check(i - 1, j + 1); } if (j < w - 1) { Check(i, j + 1); } if (i < h - 1 && j > 0) { Check(i + 1, j - 1); } if (j > 0) { Check(i, j - 1); } if (i < h - 1 && j < w - 1) { Check(i + 1, j + 1); } if (i < h - 1) { Check(i + 1, j); } return true; } return false; } static void Main(string[] args) { while (true) { int output = 0; w = 0; h = 0; if (ReadLine_2(ref w, ref h)) return; Map = new int [h][]; Checked = new bool [h][]; for (int i = 0; i < h; i++) { Map[i] = ReadLine72(); Checked[i] = new bool[w]; } for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (Check(i, j)) output++; } } Console.WriteLine(output); } } }
[["-", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22], ["+", 0, 11, 12, 227, 39, 224, 225, 226, 0, 22]]
8
851
2
using System; using System.Collections.Generic; namespace _1173 { class Program { static void Main(string[] args) { while (true) { string s = Console.ReadLine(); if (s == ".") break; Stack<char> kakko = new Stack<char>(); bool flag = true; for (int i = 0; i < s.Length; i++) { if (s[i] == '(' || s[i] == '[') kakko.Push(s[i]); else if (s[i] == ')' || s[i] == ']') { if (kakko.Count == 0) flag = false; else { char c = kakko.Pop(); if ((c != '(' && s[i] == ')') || (c != '[' && s[i] == ']')) flag = false; } } } Console.WriteLine(flag ? "yes" : "no"); } } } }
using System; using System.Collections.Generic; namespace _1173 { class Program { static void Main(string[] args) { while (true) { string s = Console.ReadLine(); if (s == ".") break; Stack<char> kakko = new Stack<char>(); bool flag = true; for (int i = 0; i < s.Length; i++) { if (s[i] == '(' || s[i] == '[') kakko.Push(s[i]); else if (s[i] == ')' || s[i] == ']') { if (kakko.Count == 0) flag = false; else { char c = kakko.Pop(); if ((c != '(' && s[i] == ')') || (c != '[' && s[i] == ']')) flag = false; } } } Console.WriteLine(flag && kakko.Count == 0 ? "yes" : "no"); } } } }
[["+", 3, 4, 0, 28, 0, 41, 15, 16, 17, 98], ["+", 0, 41, 15, 16, 12, 16, 31, 214, 205, 22], ["+", 0, 41, 15, 16, 12, 16, 31, 214, 0, 131], ["+", 0, 41, 15, 16, 12, 16, 31, 214, 141, 22], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 17, 60], ["+", 0, 28, 0, 41, 15, 16, 12, 16, 12, 203]]
8
223
6
//#define READ_FILE72 //When you want to input from a file ,define this using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY { public int X, Y; public int SQLength() { return X * X + Y * Y; } public bool Flag = false; public int ID = -1; public PointXY(int _X, int _Y, int _ID = 0) { X = _X; Y = _Y; ID = _ID; } public PointXY(PointXY P1, int _X = 0, int _Y = 0, int _ID = -1) { X = P1.X + _X; Y = P1.Y + _Y; ID = _ID; } public static bool operator ==(PointXY P1, PointXY P2) { return (P1.X == P2.X && P1.Y == P2.Y); } public static bool operator !=(PointXY P1, PointXY P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY)obj); } public string CurrentInformation() { return "x:" + X + " y:" + Y + " ID:" + ID; } public string ForWriteLineXY(bool reverse = false) { if (!reverse) return X + " " + Y; else return Y + " " + X; } } public class Lib72 { public static T[][] CopyJagArray2<T>(T[][] _Base) { T[][] NewArray = new T[_Base.Length][]; for (int i = 0; i < _Base.Length; i++) { NewArray[i] = new T[_Base[i].Length]; for (int j = 0; j < _Base[i].Length; j++) { NewArray[i][j] = _Base[i][j]; } } return NewArray; } public static T[][][] CopyJagArray3<T>(T[][][] _Base) { T[][][] NewArray = new T[_Base.Length][][]; for (int i = 0; i < _Base.Length; i++) { NewArray[i] = CopyJagArray2(_Base[i]); ; } return NewArray; } public static bool isInRect(int _X, int _Y, int _W, int _H) { return (_X >= 0 && _Y >= 0 && _X < _W && _Y < _H); } public static int NumFromChar(char CNUM) { return CNUM - 48; } public static char LoopChar52(char _C, int n) { // Char(C#) uses Uni-Code // 33 ! "#$%&'( 41 ) // 42 * +,-. 47/ // 48 0 .... 57 9 // 58 :;<=>? 64 @ // 65 A .... 90 Z // 91 [\]^_ 96` // 97 a .... 122 z int i_C = (int)_C; if (i_C > 64 && i_C < 91) i_C -= 65; // 0~25 AZ else if (i_C > 96 && i_C < 123) i_C -= 71; // 26~51 az else return '0'; int RESULT = Modulo((i_C + n), 52); if (RESULT < 26) return (char)(RESULT + 65); else return (char)(RESULT + 71); } public static int Modulo(int A, int B) { // -6 % 5 == -1 ; Modulo (-6 , 5 ) == 4 int Result = A % B; if (Result >= 0) { return Result; } else return Result + B; } public static int intFromHourMinSec(int _h, int _m, int _s) { return _s + 60 * _m + 3600 * _h; } public static int[] KETAArray(int Num) { return KETAArray(Num.ToString()); } public static int[] KETAArray(string Num) { char[] cKETA = Num.ToCharArray(); int[] iKETA = new int[cKETA.Length]; for (int i = 0; i < iKETA.Length; i++) { iKETA[i] = NumFromChar(cKETA[i]); } return iKETA; } public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; } public static int FromKETAArray(int[] _ketaarray) { int result = 0; int[] R_ketaarray = _ketaarray.Reverse().ToArray(); for (int i = 0, j = 1; i < R_ketaarray.Length; i++, j *= 10) { result += j * R_ketaarray[i]; } return result; } public static bool isPrime(int p) { if (p != 2 && p % 2 == 0) return false; if (p == 1) return false; int SQp = (int)(Math.Sqrt(p)); for (int i = 3; i <= SQp; i++) { if (p % i == 0) return false; } return true; } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true, int FinNum = 0) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == FinNum && num2 == FinNum); } static int[] ReadLine_Array(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } #if READ_FILE72 static bool FileReadLine_1(ref int num1, bool Fin0 = true) { string str = cReader.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int FileReadLine_1() { return int.Parse(cReader.ReadLine()); } static bool FileReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true, int FinNum = 0) { string str = cReader.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == FinNum && num2 == FinNum); } static int[] FileReadLine_Array(char Spliter = ' ') { return cReader.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const string ReadFileName = "Read.txt"; static bool ReadFromLocal = true; static System.IO.StreamReader cReader; #endif const int DefaultMax = 72727272; static void Main(string[] args) { #if READ_FILE72 cReader = ReadFromLocal ? new System.IO.StreamReader( System.IO.Directory.GetCurrentDirectory() + "\\" + ReadFileName, System.Text.Encoding.Unicode) : new System.IO.StreamReader( ReadFileName, System.Text.Encoding.Unicode); #endif Main72(); #if READ_FILE72 cReader.Close(); #endif } static void Main72() { while (true) { int h = 0, w = 0; // 14 27 (925)-> 21 22(925) (12 28(928)) if (ReadLine_2(ref h, ref w)) return; int BaseLength = new PointXY(w, h).SQLength(); int MinLength = int.MaxValue; var Answer = new PointXY(0, 0); // 28 74 (6260) ->5 79 (6266) (35 71 (6266)) for (int wi = 1; wi < 161; wi++) { for (int hi = wi - 1; hi > 0; hi--) { if (wi * wi + hi * hi > BaseLength && wi * wi + hi * hi < MinLength) { Answer = new PointXY(wi, hi); MinLength = Answer.SQLength(); } else if (wi * wi + hi * hi == BaseLength && wi < w) { Answer = new PointXY(wi, hi); MinLength = Answer.SQLength(); } } } Console.WriteLine(Answer.ForWriteLineXY(true)); } } }
//#define READ_FILE72 //When you want to input from a file ,define this using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY { public int X, Y; public int SQLength() { return X * X + Y * Y; } public bool Flag = false; public int ID = -1; public PointXY(int _X, int _Y, int _ID = 0) { X = _X; Y = _Y; ID = _ID; } public PointXY(PointXY P1, int _X = 0, int _Y = 0, int _ID = -1) { X = P1.X + _X; Y = P1.Y + _Y; ID = _ID; } public static bool operator ==(PointXY P1, PointXY P2) { return (P1.X == P2.X && P1.Y == P2.Y); } public static bool operator !=(PointXY P1, PointXY P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY)obj); } public string CurrentInformation() { return "x:" + X + " y:" + Y + " ID:" + ID; } public string ForWriteLineXY(bool reverse = false) { if (!reverse) return X + " " + Y; else return Y + " " + X; } } public class Lib72 { public static T[][] CopyJagArray2<T>(T[][] _Base) { T[][] NewArray = new T[_Base.Length][]; for (int i = 0; i < _Base.Length; i++) { NewArray[i] = new T[_Base[i].Length]; for (int j = 0; j < _Base[i].Length; j++) { NewArray[i][j] = _Base[i][j]; } } return NewArray; } public static T[][][] CopyJagArray3<T>(T[][][] _Base) { T[][][] NewArray = new T[_Base.Length][][]; for (int i = 0; i < _Base.Length; i++) { NewArray[i] = CopyJagArray2(_Base[i]); ; } return NewArray; } public static bool isInRect(int _X, int _Y, int _W, int _H) { return (_X >= 0 && _Y >= 0 && _X < _W && _Y < _H); } public static int NumFromChar(char CNUM) { return CNUM - 48; } public static char LoopChar52(char _C, int n) { // Char(C#) uses Uni-Code // 33 ! "#$%&'( 41 ) // 42 * +,-. 47/ // 48 0 .... 57 9 // 58 :;<=>? 64 @ // 65 A .... 90 Z // 91 [\]^_ 96` // 97 a .... 122 z int i_C = (int)_C; if (i_C > 64 && i_C < 91) i_C -= 65; // 0~25 AZ else if (i_C > 96 && i_C < 123) i_C -= 71; // 26~51 az else return '0'; int RESULT = Modulo((i_C + n), 52); if (RESULT < 26) return (char)(RESULT + 65); else return (char)(RESULT + 71); } public static int Modulo(int A, int B) { // -6 % 5 == -1 ; Modulo (-6 , 5 ) == 4 int Result = A % B; if (Result >= 0) { return Result; } else return Result + B; } public static int intFromHourMinSec(int _h, int _m, int _s) { return _s + 60 * _m + 3600 * _h; } public static int[] KETAArray(int Num) { return KETAArray(Num.ToString()); } public static int[] KETAArray(string Num) { char[] cKETA = Num.ToCharArray(); int[] iKETA = new int[cKETA.Length]; for (int i = 0; i < iKETA.Length; i++) { iKETA[i] = NumFromChar(cKETA[i]); } return iKETA; } public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; } public static int FromKETAArray(int[] _ketaarray) { int result = 0; int[] R_ketaarray = _ketaarray.Reverse().ToArray(); for (int i = 0, j = 1; i < R_ketaarray.Length; i++, j *= 10) { result += j * R_ketaarray[i]; } return result; } public static bool isPrime(int p) { if (p != 2 && p % 2 == 0) return false; if (p == 1) return false; int SQp = (int)(Math.Sqrt(p)); for (int i = 3; i <= SQp; i++) { if (p % i == 0) return false; } return true; } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true, int FinNum = 0) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == FinNum && num2 == FinNum); } static int[] ReadLine_Array(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } #if READ_FILE72 static bool FileReadLine_1(ref int num1, bool Fin0 = true) { string str = cReader.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int FileReadLine_1() { return int.Parse(cReader.ReadLine()); } static bool FileReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true, int FinNum = 0) { string str = cReader.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == FinNum && num2 == FinNum); } static int[] FileReadLine_Array(char Spliter = ' ') { return cReader.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const string ReadFileName = "Read.txt"; static bool ReadFromLocal = true; static System.IO.StreamReader cReader; #endif const int DefaultMax = 72727272; static void Main(string[] args) { #if READ_FILE72 cReader = ReadFromLocal ? new System.IO.StreamReader( System.IO.Directory.GetCurrentDirectory() + "\\" + ReadFileName, System.Text.Encoding.Unicode) : new System.IO.StreamReader( ReadFileName, System.Text.Encoding.Unicode); #endif Main72(); #if READ_FILE72 cReader.Close(); #endif } static void Main72() { while (true) { int h = 0, w = 0; // 14 27 (925)-> 21 22(925) (12 28(928)) if (ReadLine_2(ref h, ref w)) return; int BaseLength = new PointXY(w, h).SQLength(); int MinLength = int.MaxValue; var Answer = new PointXY(0, 0); // 28 74 (6260) ->5 79 (6266) (35 71 (6266)) for (int wi = 1; wi < 161; wi++) { for (int hi = wi - 1; hi > 0; hi--) { if (wi * wi + hi * hi > BaseLength && wi * wi + hi * hi <= MinLength) { Answer = new PointXY(wi, hi); MinLength = Answer.SQLength(); } else if (wi * wi + hi * hi == BaseLength && wi < w) { Answer = new PointXY(wi, hi); MinLength = Answer.SQLength(); } } } Console.WriteLine(Answer.ForWriteLineXY(true)); } } }
[["-", 8, 196, 0, 57, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 57, 15, 16, 12, 16, 17, 19]]
8
1,712
2
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApplication1 { class ClassMain { public static bool[] primes = Enumerable.Repeat(true, 1500000 + 1).ToArray(); public static void sieve() { primes[0] = false; primes[1] = false; for (int i = 2; i < primes.Length / 2 + 1; i++) { if (primes[i]) { for (int j = 2; j * i < primes.Length; j++) { primes[i * j] = false; } } } } public static void Main(String[] args) { string line; sieve(); while ((line = Console.ReadLine()) != null) { // int[] ints = line.Split(' ').Select(int.Parse).ToArray(); // int n = ints[0]; int n = int.Parse(line); if (n == 0) { break; } if (primes[n]) { Console.WriteLine(0); } else { int moreThanCnt = 0; int lessThanCnt = 0; for (int i = 1; i + n < 1500000 + 1; i++) { if (primes[i + n] == false) { moreThanCnt++; } else { break; } } for (int i = 1; n - i > 1; i++) { if (primes[n - i] == false) { lessThanCnt++; } else { break; } } Console.WriteLine(moreThanCnt + lessThanCnt + 1); } } } } }
using System; using System.Linq; using System.Collections.Generic; namespace ConsoleApplication1 { class ClassMain { public static bool[] primes = Enumerable.Repeat(true, 1500000 + 1).ToArray(); public static void sieve() { primes[0] = false; primes[1] = false; for (int i = 2; i < primes.Length / 2 + 1; i++) { if (primes[i]) { for (int j = 2; j * i < primes.Length; j++) { primes[i * j] = false; } } } } public static void Main(String[] args) { string line; sieve(); while ((line = Console.ReadLine()) != null) { // int[] ints = line.Split(' ').Select(int.Parse).ToArray(); // int n = ints[0]; int n = int.Parse(line); if (n == 0) { break; } if (primes[n]) { Console.WriteLine(0); } else { int moreThanCnt = 0; int lessThanCnt = 0; for (int i = 1; i + n < 1500000 + 1; i++) { if (primes[i + n] == false) { moreThanCnt++; } else { break; } } for (int i = 1; n - i > 1; i++) { if (primes[n - i] == false) { lessThanCnt++; } else { break; } } Console.WriteLine(moreThanCnt + lessThanCnt + 2); } } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
304
2
using System; namespace _1356 { class Program { static void Main(string[] args) { Console.ReadLine(); string s = ""; while (true) { string a = Console.ReadLine(); if (string.IsNullOrEmpty(a)) break; string[] x = a.Split(); s += string.Join("", x); } for (int i = 1; true; i++) { string now = i.ToString(); if (s.IndexOf(now) < 0) { Console.WriteLine(i); break; } } } } }
using System; namespace _1356 { class Program { static void Main(string[] args) { Console.ReadLine(); string s = ""; while (true) { string a = Console.ReadLine(); if (string.IsNullOrEmpty(a)) break; string[] x = a.Split(); s += string.Join("", x); } for (int i = 0; true; i++) { string now = i.ToString(); if (s.IndexOf(now) < 0) { Console.WriteLine(i); break; } } } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203]]
8
128
2
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var aL = "abcdefghijklmnopqrstuvwxyz"; var d = new Dictionary<char, int>(); for (int i = 0; i < 26; i++) d[aL[i]] = i; var a = new int[26]; var b = new int[26]; var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); var t = Console.ReadLine().Trim(); for (int i = 0; i < n; i++) { a[d[s[i]]]++; b[d[t[i]]]++; } var a2 = a.Where(x => x >= 2).OrderByDescending(x => x).ToArray(); var b2 = b.Where(x => x >= 1).OrderByDescending(x => x).ToArray(); var imin = Math.Min(a2.Length, b2.Length); for (int i = 0; i < imin; i++) a2[i] = Math.Max(a2[i] - b2[i], 0); Console.WriteLine(a2.Sum()); } }
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var aL = "abcdefghijklmnopqrstuvwxyz"; var d = new Dictionary<char, int>(); for (int i = 0; i < 26; i++) d[aL[i]] = i; var a = new int[26]; var b = new int[26]; var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); var t = Console.ReadLine().Trim(); for (int i = 0; i < n; i++) { a[d[s[i]]]++; b[d[t[i]]]++; } var a2 = a.Where(x => x >= 1).OrderByDescending(x => x).ToArray(); var b2 = b.Where(x => x >= 1).OrderByDescending(x => x).ToArray(); var imin = Math.Min(a2.Length, b2.Length); for (int i = 0; i < imin; i++) a2[i] = Math.Max(a2[i] - b2[i], 0); Console.WriteLine(a2.Sum()); } }
[["-", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 203]]
8
287
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication32 { class Program { static void Main() { int[] a = new int[3]; int c, d, f; d = c = f = 0; for (int b = 0; b < 4; b++) { a[b] = int.Parse(Console.ReadLine()); } for (int e = 0; e < 4; e++) c += a[e]; d += c / 60; f += c % 60; Console.WriteLine(d); Console.WriteLine(f); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication32 { class Program { static void Main() { int[] a = new int[4]; int c, d, f; d = c = f = 0; for (int b = 0; b < 4; b++) { a[b] = int.Parse(Console.ReadLine()); } for (int e = 0; e < 4; e++) c += a[e]; d += c / 60; f += c % 60; Console.WriteLine(d); Console.WriteLine(f); } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203]]
8
140
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { string search = line; int n = int.Parse(Console.ReadLine()); int cnt = 0; for (int i = 0; i < n; i++) { line = Console.ReadLine(); string tail = line.Substring(0, search.Length - 1); line += tail; for (int j = 0; j <= line.Length - search.Length; j++) { if (line.Substring(j).StartsWith(search)) { cnt++; break; } } } Console.WriteLine(line); break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { string search = line; int n = int.Parse(Console.ReadLine()); int cnt = 0; for (int i = 0; i < n; i++) { line = Console.ReadLine(); string tail = line.Substring(0, search.Length - 1); line += tail; for (int j = 0; j <= line.Length - search.Length; j++) { if (line.Substring(j).StartsWith(search)) { cnt++; break; } } } Console.WriteLine(cnt); break; } } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
179
2
using System; class Program { static void Main() { string s = Console.ReadLine(); int n = int.Parse(Console.ReadLine()); int ret = 0; for (int i = 0; i < n; i++) { string t = Console.ReadLine(); t += t; for (int j = 0; j <= t.Length - s.Length; j++) { if (t.Substring(j, 4) == s) { ret++; break; } } } Console.WriteLine(ret); } }
using System; class Program { static void Main() { string s = Console.ReadLine(); int n = int.Parse(Console.ReadLine()); int ret = 0; for (int i = 0; i < n; i++) { string t = Console.ReadLine(); t += t; for (int j = 0; j <= t.Length - s.Length; j++) { if (t.Substring(j, s.Length) == s) { ret++; break; } } } Console.WriteLine(ret); } }
[["-", 15, 16, 31, 213, 3, 4, 0, 28, 0, 203], ["+", 31, 213, 3, 4, 0, 28, 0, 214, 205, 22], ["+", 31, 213, 3, 4, 0, 28, 0, 214, 0, 131], ["+", 31, 213, 3, 4, 0, 28, 0, 214, 141, 22]]
8
120
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { double a, b, c, d, e; a = double.Parse(Console.ReadLine()); b = double.Parse(Console.ReadLine()); c = double.Parse(Console.ReadLine()); d = double.Parse(Console.ReadLine()); e = double.Parse(Console.ReadLine()); double[] f = new double[2]; f[0] = Math.Ceiling(b / d); f[1] = Math.Ceiling(c / e); Array.Sort(f); Console.WriteLine(a - f[0]); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { double a, b, c, d, e; a = double.Parse(Console.ReadLine()); b = double.Parse(Console.ReadLine()); c = double.Parse(Console.ReadLine()); d = double.Parse(Console.ReadLine()); e = double.Parse(Console.ReadLine()); double[] f = new double[2]; f[0] = Math.Ceiling(b / d); f[1] = Math.Ceiling(c / e); Array.Sort(f); Console.WriteLine(a - f[1]); } } }
[["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203]]
8
169
2
using System.Collections.Generic; using System; public class hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); var sL = s.Length; var ans = 0; for (int i = 0; i < n; i++) { var t = Console.ReadLine().Trim(); var tL = t.Length; var slist = new List<int>(); var a = 0; while (true) { var a0 = t.IndexOf(s[0], a); if (a0 >= 0) { slist.Add(a0); a = a0 + 1; } else break; } foreach (var start in slist) { var chkL = (tL - start) / (sL - 1); for (int j = 1; j <= chkL; j++) { var str = ""; for (int k = 1; k <= sL; k++) { var chk = j * (k - 1) + start; if (chk > tL - 1) goto nextloop; str += t.Substring(chk, 1); } if (str == s) { ans++; goto nextloop; } } } nextloop:; } Console.WriteLine(ans); } }
using System.Collections.Generic; using System; public class hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var s = Console.ReadLine().Trim(); var sL = s.Length; var ans = 0; for (int i = 0; i < n; i++) { var t = Console.ReadLine().Trim(); var tL = t.Length; var slist = new List<int>(); var a = 0; while (true) { var a0 = t.IndexOf(s[0], a); if (a0 >= 0) { slist.Add(a0); a = a0 + 1; } else break; } foreach (var start in slist) { var chkL = (tL - start) / (sL - 1); for (int j = 1; j <= chkL; j++) { var str = ""; for (int k = 1; k <= sL; k++) { var chk = j * (k - 1) + start; if (chk > tL - 1) goto next; str += t.Substring(chk, 1); } if (str == s) { ans++; goto nextloop; } } next:; } nextloop:; } Console.WriteLine(ans); } }
[["-", 0, 7, 8, 196, 0, 57, 64, 126, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 64, 126, 0, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 97, 0, 22], ["+", 8, 196, 0, 210, 8, 196, 0, 97, 0, 102], ["+", 0, 210, 8, 196, 0, 97, 0, 260, 0, 35]]
8
284
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int s = 0; for (int c = 0; c < a; c++) { int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray(); b += d[0] - d[1]; if (b > s) s = b; if (b < 0) { Console.WriteLine(0); break; } } Console.WriteLine(s); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int s = 0; for (int c = 0; c < a; c++) { int[] d = Console.ReadLine().Split().Select(int.Parse).ToArray(); b += d[0] - d[1]; if (b > s) s = b; if (b < 0) { s = 0; break; } } Console.WriteLine(s); } } }
[["-", 64, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 64, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 64, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25]]
8
156
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0588 { class Program { static void Main(string[] args) { long n = 0; long a = 0; while (true) { if (n == 0) { a = long.Parse(Console.ReadLine()); continue; } string s = Console.ReadLine(); if (s == "=") { Console.WriteLine(a); break; } long d = long.Parse(Console.ReadLine()); if (s == "-") { a -= d; } if (s == "+") { a += d; } if (s == "*") { a = a * d; } if (s == "/") { a /= d; } n++; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0588 { class Program { static void Main(string[] args) { long n = 0; long a = 0; while (true) { if (n == 0) { a = long.Parse(Console.ReadLine()); } string s = Console.ReadLine(); if (s == "=") { Console.WriteLine(a); break; } long d = long.Parse(Console.ReadLine()); if (s == "-") { a -= d; } if (s == "+") { a += d; } if (s == "*") { a = a * d; } if (s == "/") { a /= d; } n++; } } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 35]]
8
181
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { int s = 0; for (int a = 0; a < 5; a++) { int b = int.Parse(Console.ReadLine()); if (b < 40) s += 40; else s += b; } Console.WriteLine(s); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { int s = 0; for (int a = 0; a < 5; a++) { int b = int.Parse(Console.ReadLine()); if (b < 40) s += 40; else s += b; } Console.WriteLine(s / 5); } } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
92
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int[] ints = line.Split(' ').Select(int.Parse).ToArray(); // int n = int.Parse(line); int n = ints[0]; int m = ints[1]; if (n == 0) { break; } int[] prices = new int[n]; for (int i = 0; i < n; i++) { prices[i] = int.Parse(Console.ReadLine()); } int[] votes = new int[n]; for (int i = 0; i < m; i++) { int rank = int.Parse(Console.ReadLine()); for (int priceInd = 0; priceInd < n; priceInd++) { if (rank >= prices[i]) { votes[i]++; break; } } } int max = -1; int maxKyougi = -1; for (int i = 0; i < n; i++) { if (max < votes[i]) { max = votes[i]; maxKyougi = i; } } Console.WriteLine(maxKyougi + 1); break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int[] ints = line.Split(' ').Select(int.Parse).ToArray(); // int n = int.Parse(line); int n = ints[0]; int m = ints[1]; if (n == 0) { break; } int[] prices = new int[n]; for (int i = 0; i < n; i++) { prices[i] = int.Parse(Console.ReadLine()); } int[] votes = new int[n]; for (int i = 0; i < m; i++) { int rank = int.Parse(Console.ReadLine()); for (int priceInd = 0; priceInd < n; priceInd++) { if (rank >= prices[priceInd]) { votes[priceInd]++; break; } } } int max = -1; int maxKyougi = -1; for (int i = 0; i < n; i++) { if (max < votes[i]) { max = votes[i]; maxKyougi = i; } } Console.WriteLine(maxKyougi + 1); break; } } } }
[["-", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["+", 15, 16, 12, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 223, 0, 204, 206, 207, 0, 28, 0, 22]]
8
291
4
using System; using System.IO; class Program { void Calc() { var sc = new Scanner(); int kyougisuu = sc.NextInt(); int ninnzuu = sc.NextInt(); int[] nedann = new int[kyougisuu]; int nums = 1; for (int i = 0; i < kyougisuu; i++) { nedann[i] = sc.NextInt(); } int[] kyougi = new int[kyougisuu]; for (int iin = 0; iin < ninnzuu; iin++) { int sinsaa = int.Parse(Console.ReadLine()); for (int k = 0; k < kyougisuu; k++) { if (sinsaa >= nedann[k]) { kyougi[k] += 1; break; } } } int a = kyougi[0]; for (int i = 0; i < kyougisuu - 1; i++) { if (a >= kyougi[i + 1]) { } else { a = kyougi[i + 1]; nums = i + 1; } } Console.WriteLine(nums); } static void Main() { byte[] inputBuffer = new byte[1024]; Stream inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); new Program().Calc(); } class Scanner { string[] s = new string[0]; int i = 0; char[] cs = new char[] { ' ' }; public string Next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } }
using System; using System.IO; class Program { void Calc() { var sc = new Scanner(); int kyougisuu = sc.NextInt(); int ninnzuu = sc.NextInt(); int[] nedann = new int[kyougisuu]; int nums = 1; for (int i = 0; i < kyougisuu; i++) { nedann[i] = sc.NextInt(); } int[] kyougi = new int[kyougisuu]; for (int iin = 0; iin < ninnzuu; iin++) { int sinsaa = int.Parse(Console.ReadLine()); for (int k = 0; k < kyougisuu; k++) { if (sinsaa >= nedann[k]) { kyougi[k] += 1; break; } } } int a = kyougi[0]; for (int i = 0; i < kyougisuu - 1; i++) { if (a >= kyougi[i + 1]) { } else { a = kyougi[i + 1]; nums = i + 2; } } Console.WriteLine(nums); } static void Main() { byte[] inputBuffer = new byte[1024]; Stream inputStream = Console.OpenStandardInput(inputBuffer.Length); Console.SetIn(new StreamReader(inputStream, Console.InputEncoding, false, inputBuffer.Length)); new Program().Calc(); } class Scanner { string[] s = new string[0]; int i = 0; char[] cs = new char[] { ' ' }; public string Next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } }
[["-", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 203]]
8
424
2
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); var an = new List<int>(); var pre1 = false; var count = 1; if (a[0] == 1) pre1 = true; for (int i = 1; i < n; i++) { if (pre1 && a[i] == 0) { count++; pre1 = false; } else if (!pre1 && a[i] == 1) { count++; pre1 = true; } else { an.Add(count); count = 1; } } an.Add(count); Console.WriteLine(getMax(an)); } public static int getMax(List<int> an) { if (an.Count() == 1) return 0; if (an.Count() == 2) return an.Sum(); var a = an.ToArray(); var n = a.Length; var s3 = a[0] + a[1] + a[2]; var smax = s3; for (int i = 3; i < n; i++) { s3 = s3 + a[i] - a[i - 3]; smax = Math.Max(smax, s3); } return smax; } }
using System.Linq; using System.Collections.Generic; using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); var an = new List<int>(); var pre1 = false; var count = 1; if (a[0] == 1) pre1 = true; for (int i = 1; i < n; i++) { if (pre1 && a[i] == 0) { count++; pre1 = false; } else if (!pre1 && a[i] == 1) { count++; pre1 = true; } else { an.Add(count); count = 1; } } an.Add(count); Console.WriteLine(getMax(an)); } public static int getMax(List<int> an) { if (an.Count() == 1) return an[0]; if (an.Count() == 2) return an.Sum(); var a = an.ToArray(); var n = a.Length; var s3 = a[0] + a[1] + a[2]; var smax = s3; for (int i = 3; i < n; i++) { s3 = s3 + a[i] - a[i - 3]; smax = Math.Max(smax, s3); } return smax; } }
[["+", 8, 196, 0, 57, 64, 37, 0, 204, 205, 22], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 70], ["+", 0, 57, 64, 37, 0, 204, 206, 207, 0, 73]]
8
333
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); int d = int.Parse(Console.ReadLine()); int e = int.Parse(Console.ReadLine()); int X = a * e; int Y = b; if (e > c) { Y += (e - c) * d; } if (X > Y) Console.WriteLine(X); else Console.WriteLine(Y); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication51 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); int b = int.Parse(Console.ReadLine()); int c = int.Parse(Console.ReadLine()); int d = int.Parse(Console.ReadLine()); int e = int.Parse(Console.ReadLine()); int X = a * e; int Y = b; if (e > c) { Y += (e - c) * d; } if (X < Y) Console.WriteLine(X); else Console.WriteLine(Y); } } }
[["-", 0, 195, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 195, 8, 196, 0, 57, 15, 16, 17, 18]]
8
156
2
using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); if (n == 1) { Console.WriteLine(1); goto end; } var k = int.Parse(line[1]); var a = new long[n - 1]; var pre = int.Parse(Console.ReadLine().Trim()); var t0 = pre; var last = 0L; for (int i = 0; i < n - 1; i++) { var w = int.Parse(Console.ReadLine().Trim()); a[i] = w - pre - 1; pre = w; if (i == n - 2) last = w; } var ret = last - t0 - 1 - a.OrderByDescending(x => x).Take(k - 1).Sum(); Console.WriteLine(ret); end:; } }
using System.Linq; using System; public class Hello { public static void Main() { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); if (n == 1) { Console.WriteLine(1); goto end; } var k = int.Parse(line[1]); var a = new long[n - 1]; var pre = int.Parse(Console.ReadLine().Trim()); var t0 = pre; var last = 0L; for (int i = 0; i < n - 1; i++) { var w = int.Parse(Console.ReadLine().Trim()); a[i] = w - pre - 1; pre = w; if (i == n - 2) last = w; } var ret = last - t0 + 1 - a.OrderByDescending(x => x).Take(k - 1).Sum(); Console.WriteLine(ret); end:; } }
[["-", 0, 200, 0, 212, 0, 16, 31, 16, 17, 33], ["+", 0, 200, 0, 212, 0, 16, 31, 16, 17, 72]]
8
228
2
using System; class Program { static void Main() { bool cont = true; while (cont) cont = Sub(); } static bool Sub() { string[] raw1 = Console.ReadLine().Split(' '); if (raw1[0] == "0") return false; int n = int.Parse(raw1[0]); int k = int.Parse(raw1[1]); string[] rawS = Console.ReadLine().Split(' '); int[] s = new int[k]; for (int i = 0; i < k; i++) s[i] = int.Parse(rawS[i]); int[] sum = new int[k]; for (int i = 0; i < n; i++) { string[] rawB = Console.ReadLine().Split(' '); for (int j = 0; j < k; j++) sum[j] += int.Parse(rawB[j]); } for (int i = 0; i < k; i++) { if (sum[i] > s[i]) { Console.WriteLine("NO"); return true; } } Console.WriteLine("Yes"); return true; } }
using System; class Program { static void Main() { bool cont = true; while (cont) cont = Sub(); } static bool Sub() { string[] raw1 = Console.ReadLine().Split(' '); if (raw1[0] == "0") return false; int n = int.Parse(raw1[0]); int k = int.Parse(raw1[1]); string[] rawS = Console.ReadLine().Split(' '); int[] s = new int[k]; for (int i = 0; i < k; i++) s[i] = int.Parse(rawS[i]); int[] sum = new int[k]; for (int i = 0; i < n; i++) { string[] rawB = Console.ReadLine().Split(' '); for (int j = 0; j < k; j++) sum[j] += int.Parse(rawB[j]); } for (int i = 0; i < k; i++) { if (sum[i] > s[i]) { Console.WriteLine("No"); return true; } } Console.WriteLine("Yes"); return true; } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
280
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0098 { public class Program { public static void Main(string[] args) { int n = RInt(); int[,] cSum = new int[n + 1, n + 1]; //累積和の作成 for (int i = 0; i < n; i++) { int[] items = RIntAr(); for (int j = 0; j < n; j++) { cSum[i + 1, j + 1] = cSum[i, j + 1] + cSum[i + 1, j] - cSum[i, j] + items[j]; } } int max = int.MinValue; //部分和のチェック for (int xs = 0; xs < n; xs++) { for (int xt = xs + 1; xt < n + 1; xt++) { for (int ys = 0; ys < n; ys++) { for (int yt = 0; yt < n + 1; yt++) { max = Math.Max( cSum[yt, xt] - cSum[yt, xs] - cSum[ys, xt] + cSum[ys, xs], max); } } } } Console.WriteLine(max); } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0098 { public class Program { public static void Main(string[] args) { int n = RInt(); int[,] cSum = new int[n + 1, n + 1]; //累積和の作成 for (int i = 0; i < n; i++) { int[] items = RIntAr(); for (int j = 0; j < n; j++) { cSum[i + 1, j + 1] = cSum[i, j + 1] + cSum[i + 1, j] - cSum[i, j] + items[j]; } } int max = int.MinValue; //部分和のチェック for (int xs = 0; xs < n; xs++) { for (int xt = xs + 1; xt < n + 1; xt++) { for (int ys = 0; ys < n; ys++) { for (int yt = ys + 1; yt < n + 1; yt++) { max = Math.Max( cSum[yt, xt] - cSum[yt, xs] - cSum[ys, xt] + cSum[ys, xs], max); } } } } Console.WriteLine(max); } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 31, 22], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["+", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
563
4
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var map = new int[n + 1, n + 1]; for (int i = 0; i < n; i++) { var w = 0; string[] line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < n; j++) { map[i + 1, j + 1] = int.Parse(line[j]) + w; w = map[i + 1, j + 1]; } } for (int i = 0; i < n; i++) { var w = 0; for (int j = 0; j < n; j++) { map[j + 1, i + 1] = map[j + 1, i + 1] + w; w = map[j + 1, i + 1]; } } Console.WriteLine(n == 1 ? map[1, 1] : getAns(map)); } public static int getAns(int[,] map) { var n = map.GetLength(0); var ret = 0; for (int i = 1; i < n; i++) for (int j = i + 1; j < n; j++) for (int k = 1; k < n; k++) for (int L = k + 1; L < n; L++) { var w = map[j, L] - map[j, k - 1] - map[i - 1, L] + map[i - 1, k - 1]; ret = Math.Max(ret, w); } return ret; } }
using System; public class Hello { public static void Main() { var n = int.Parse(Console.ReadLine().Trim()); var map = new int[n + 1, n + 1]; for (int i = 0; i < n; i++) { var w = 0; string[] line = Console.ReadLine().Trim().Split(' '); for (int j = 0; j < n; j++) { map[i + 1, j + 1] = int.Parse(line[j]) + w; w = map[i + 1, j + 1]; } } for (int i = 0; i < n; i++) { var w = 0; for (int j = 0; j < n; j++) { map[j + 1, i + 1] = map[j + 1, i + 1] + w; w = map[j + 1, i + 1]; } } Console.WriteLine(n == 1 ? map[1, 1] : getAns(map)); } public static int getAns(int[,] map) { var n = map.GetLength(0); var ret = -999999999; for (int i = 1; i < n; i++) for (int j = i; j < n; j++) for (int k = 1; k < n; k++) for (int L = k; L < n; L++) { var w = map[j, L] - map[j, k - 1] - map[i - 1, L] + map[i - 1, k - 1]; ret = Math.Max(ret, w); } return ret; } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 241, 0, 203], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 17, 72], ["-", 10, 198, 0, 200, 0, 212, 0, 16, 12, 203]]
8
382
7
using System; using System.Collections.Generic; using System.Linq; namespace AIZU { class VT : IComparable, IComparable<VT> { public int s; public int V; public VT(int a, int c) { s = a; V = c; } #region Compare public static int Sign(VT a, VT b) { return Math.Sign(a.V - b.V); } public int CompareTo(VT g) { if (g == null) return 1; if (V == g.V) return -(s.CompareTo(g.s)); return V.CompareTo(g.V); } public int CompareTo(object obj) { if (obj == null) return 1; if (GetType() != obj.GetType()) { throw new ArgumentException(); } return CompareTo((VT)obj); } // http://dobon.net/vb/dotnet/programing/icomparable.html #endregion } class PriorityQueue<T> where T : IComparable<T> { #region FieldAndInitialize // http://ufcpp.net/study/algorithm/col_heap.html List<T> me = new List<T>(); List<int> Member = new List<int>(); static Func<T, T, int> Sign = (i, j) => i.CompareTo(j); static Func<T, int> ID = i => i.GetHashCode(); public PriorityQueue() {} public PriorityQueue(Func<T, T, int> F) { Sign = F; } public PriorityQueue(Func<T, int> F) { ID = F; } #endregion #region Control static void PushHeap(List<T> array, List<int> member, Func<T, int> ID, T elem) { int N = array.Count; array.Add(elem); // index of last equals to N member.Add(ID(elem)); while (N != 0) { int i = (N - 1) >> 1; // i represents N's parent if (Sign(array[N], array[i]) > 0) { // N bigger than i T tmp = array[N]; array[N] = array[i]; array[i] = tmp; int tnp = member[N]; member[N] = member[i]; member[i] = tnp; } // swap N = i; // update } } static T PopHeap(List<T> array, List<int> member, Func<T, int> ID) { int N = array.Count - 1; // last index T peek = array[0]; array[0] = array[N]; // paint out root array.RemoveAt(N); member[0] = member[N]; member.RemoveAt(N); for (int i = 0, j; (j = 2 * i + 1) < N;) { // j is the left child of i if (j != N - 1 && Sign(array[j], array[j + 1]) < 0) // not last and inferior to next j++; if (Sign(array[i], array[j]) < 0) { // i inf to j T tmp = array[j]; array[j] = array[i]; array[i] = tmp; int tnp = member[N]; member[N] = member[i]; member[i] = tnp; } // swap i = j; } return peek; } static void HeapReplace(List<T> array, List<int> member, Func<T, int> ID, int index, T NEW) { bool exceling = Sign(array[index], NEW) < 0; array[index] = NEW; member[index] = ID(NEW); if (exceling) { // ascend int N = index; while (N != 0) { int i = (N - 1) >> 1; // i represents N's parent if (Sign(array[N], array[i]) > 0) { // N bigger than i T tmp = array[N]; array[N] = array[i]; array[i] = tmp; int tnp = member[N]; member[N] = member[i]; member[i] = tnp; } // swap N = i; // update } } else { // descend int N = array.Count; for (int i = index, j; (j = 2 * i + 1) < N;) { // j is the left child of i if (j != N - 1 && Sign(array[j], array[j + 1]) < 0) // not last and inferior to next j++; if (Sign(array[i], array[j]) < 0) { // i inf to j T tmp = array[j]; array[j] = array[i]; array[i] = tmp; int tnp = member[N]; member[N] = member[i]; member[i] = tnp; } // swap i = j; } } } #endregion #region Data public void Push(T elem) { PushHeap(me, Member, ID, elem); } public T Pop() { return PopHeap(me, Member, ID); } public T Top { get { return me[0]; } } public int Count { get { return me.Count; } } public int HeapIndex(Func<T, bool> data) { return me.FindIndex(i => data(i)); } public int HeapIndex(int d) { return Member.IndexOf(d); } public void Gain(T NEW, int index) { HeapReplace(me, Member, ID, index, NEW); } public T Access(int t) { if (t >= me.Count) return default(T); else return me[t]; } #endregion } class Program { #region Reserve static int cin() { return cin(-1); } static int cin(int D) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return D; return int.Parse(s); } static int[] cins(char spliter) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return new int[] {}; string[] ss = s.Split(spliter); int[] Res = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) Res[i] = int.Parse(ss[i]); return Res; } static int[] cins() { return cins(' '); } static void print(object j) { Console.WriteLine(j.ToString()); } static void print(string j) { Console.WriteLine(j); } #endregion static PriorityQueue<VT> Fish; static void Main(string[] args) { Fish = new PriorityQueue<VT>(i => i.s); int[] I = cins(); int q = I[1]; HashSet<int> Unique = new HashSet<int>(); for (int iop = 0; iop < q; iop++) { I = cins(); if (!Unique.Contains(I[0])) Fish.Push(new VT(I[0], I[1])); else { int k = Fish.HeapIndex(I[0]); VT p = Fish.Access(k); Fish.Gain(new VT(I[0], p.V + I[1]), k); } var Res = Fish.Top; if (Res.V == 0) Console.WriteLine("1 0"); else Console.WriteLine("{0} {1}", Res.s, Res.V); Unique.Add(I[0]); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AIZU { class VT : IComparable, IComparable<VT> { public int s; public int V; public VT(int a, int c) { s = a; V = c; } #region Compare public static int Sign(VT a, VT b) { return Math.Sign(a.V - b.V); } public int CompareTo(VT g) { if (g == null) return 1; if (V == g.V) return -(s.CompareTo(g.s)); return V.CompareTo(g.V); } public int CompareTo(object obj) { if (obj == null) return 1; if (GetType() != obj.GetType()) { throw new ArgumentException(); } return CompareTo((VT)obj); } // http://dobon.net/vb/dotnet/programing/icomparable.html #endregion } class PriorityQueue<T> where T : IComparable<T> { #region FieldAndInitialize // http://ufcpp.net/study/algorithm/col_heap.html List<T> me = new List<T>(); List<int> Member = new List<int>(); static Func<T, T, int> Sign = (i, j) => i.CompareTo(j); static Func<T, int> ID = i => i.GetHashCode(); public PriorityQueue() {} public PriorityQueue(Func<T, T, int> F) { Sign = F; } public PriorityQueue(Func<T, int> F) { ID = F; } #endregion #region Control static void PushHeap(List<T> array, List<int> member, Func<T, int> ID, T elem) { int N = array.Count; array.Add(elem); // index of last equals to N member.Add(ID(elem)); while (N != 0) { int i = (N - 1) >> 1; // i represents N's parent if (Sign(array[N], array[i]) > 0) { // N bigger than i T tmp = array[N]; array[N] = array[i]; array[i] = tmp; int tnp = member[N]; member[N] = member[i]; member[i] = tnp; } // swap N = i; // update } } static T PopHeap(List<T> array, List<int> member, Func<T, int> ID) { int N = array.Count - 1; // last index T peek = array[0]; array[0] = array[N]; // paint out root array.RemoveAt(N); member[0] = member[N]; member.RemoveAt(N); for (int i = 0, j; (j = 2 * i + 1) < N;) { // j is the left child of i if (j != N - 1 && Sign(array[j], array[j + 1]) < 0) // not last and inferior to next j++; if (Sign(array[i], array[j]) < 0) { // i inf to j T tmp = array[j]; array[j] = array[i]; array[i] = tmp; int tnp = member[j]; member[j] = member[i]; member[i] = tnp; } // swap i = j; } return peek; } static void HeapReplace(List<T> array, List<int> member, Func<T, int> ID, int index, T NEW) { bool exceling = Sign(array[index], NEW) < 0; array[index] = NEW; member[index] = ID(NEW); if (exceling) { // ascend int N = index; while (N != 0) { int i = (N - 1) >> 1; // i represents N's parent if (Sign(array[N], array[i]) > 0) { // N bigger than i T tmp = array[N]; array[N] = array[i]; array[i] = tmp; int tnp = member[N]; member[N] = member[i]; member[i] = tnp; } // swap N = i; // update } } else { // descend int N = array.Count; for (int i = index, j; (j = 2 * i + 1) < N;) { // j is the left child of i if (j != N - 1 && Sign(array[j], array[j + 1]) < 0) // not last and inferior to next j++; if (Sign(array[i], array[j]) < 0) { // i inf to j T tmp = array[j]; array[j] = array[i]; array[i] = tmp; int tnp = member[j]; member[j] = member[i]; member[i] = tnp; } // swap i = j; } } } #endregion #region Data public void Push(T elem) { PushHeap(me, Member, ID, elem); } public T Pop() { return PopHeap(me, Member, ID); } public T Top { get { return me[0]; } } public int Count { get { return me.Count; } } public int HeapIndex(Func<T, bool> data) { return me.FindIndex(i => data(i)); } public int HeapIndex(int d) { return Member.IndexOf(d); } public void Gain(T NEW, int index) { HeapReplace(me, Member, ID, index, NEW); } public T Access(int t) { if (t >= me.Count) return default(T); else return me[t]; } #endregion } class Program { #region Reserve static int cin() { return cin(-1); } static int cin(int D) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return D; return int.Parse(s); } static int[] cins(char spliter) { string s = Console.ReadLine(); if (string.IsNullOrEmpty(s)) return new int[] {}; string[] ss = s.Split(spliter); int[] Res = new int[ss.Length]; for (int i = 0; i < ss.Length; i++) Res[i] = int.Parse(ss[i]); return Res; } static int[] cins() { return cins(' '); } static void print(object j) { Console.WriteLine(j.ToString()); } static void print(string j) { Console.WriteLine(j); } #endregion static PriorityQueue<VT> Fish; static void Main(string[] args) { Fish = new PriorityQueue<VT>(i => i.s); int[] I = cins(); int q = I[1]; HashSet<int> Unique = new HashSet<int>(); for (int iop = 0; iop < q; iop++) { I = cins(); if (!Unique.Contains(I[0])) Fish.Push(new VT(I[0], I[1])); else { int k = Fish.HeapIndex(I[0]); VT p = Fish.Access(k); Fish.Gain(new VT(I[0], p.V + I[1]), k); } var Res = Fish.Top; if (Res.V == 0) Console.WriteLine("1 0"); else Console.WriteLine("{0} {1}", Res.s, Res.V); Unique.Add(I[0]); } } } }
[["-", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 212, 0, 204, 206, 207, 0, 28, 0, 22], ["-", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 0, 11, 31, 204, 206, 207, 0, 28, 0, 22]]
8
1,594
8
using System; using System.Collections; public class p0100 { p0100() { string str; string[] st; int n, p; bool f; ArrayList al = new ArrayList(); decimal[] sm = new decimal[4001]; while ((str = Console.ReadLine()) != null && str != "0") { n = int.Parse(str); f = true; for (int i = 0; i < 4001; ++i) sm[i] = 0; while (0 < n--) { st = (Console.ReadLine()).Split(' '); p = int.Parse(st[0]); sm[p] += decimal.Parse(st[1]) * decimal.Parse(st[0]); if (!al.Contains(p)) al.Add(p); } foreach (int i in al) if (sm[i] >= 1000000) { Console.WriteLine("{0}", i); f = false; } if (f) Console.WriteLine("NA"); al.Clear(); } } public static int Main(string[] args) { new p0100(); return 0; } }
using System; using System.Collections; public class p0100 { p0100() { string str; string[] st; int n, p; bool f; ArrayList al = new ArrayList(); decimal[] sm = new decimal[4001]; while ((str = Console.ReadLine()) != null && str != "0") { n = int.Parse(str); f = true; for (int i = 0; i < 4001; ++i) sm[i] = 0; while (0 < n--) { st = (Console.ReadLine()).Split(' '); p = int.Parse(st[0]); sm[p] += decimal.Parse(st[1]) * decimal.Parse(st[2]); if (!al.Contains(p)) al.Add(p); } foreach (int i in al) if (sm[i] >= 1000000) { Console.WriteLine("{0}", i); f = false; } if (f) Console.WriteLine("NA"); al.Clear(); } } public static int Main(string[] args) { new p0100(); return 0; } }
[["-", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203], ["+", 0, 28, 0, 204, 206, 207, 0, 28, 0, 203]]
8
261
2
using System; namespace TestProject { class MainClass { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string s0 = "Hoshino"; string s1 = "Hoshina"; string[] s = new string[n]; for (int i = 0; i < n; i++) { s[i] = Console.ReadLine(); s[i].Replace(s0, s1); } foreach (var x in s) { Console.WriteLine(x); } } } }
using System; namespace TestProject { class MainClass { public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); string s0 = "Hoshino"; string s1 = "Hoshina"; string[] s = new string[n]; for (int i = 0; i < n; i++) { s[i] = Console.ReadLine(); s[i] = s[i].Replace(s0, s1); } foreach (var x in s) { Console.WriteLine(x); } } } }
[["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32], ["+", 0, 11, 12, 213, 63, 214, 205, 204, 205, 22], ["+", 12, 213, 63, 214, 205, 204, 206, 207, 0, 70], ["+", 63, 214, 205, 204, 206, 207, 0, 28, 0, 22], ["+", 12, 213, 63, 214, 205, 204, 206, 207, 0, 73]]
8
117
5
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication35 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); int change = 0; while (true) { int @out = 0, j = 0; bool[] runner = { false, false, false }; while (true) { string y = Console.ReadLine(); j++; switch (y[1]) { case 'I': runner[2] = runner[1]; runner[1] = runner[0]; runner[0] = false; break; case 'U': if (@out++ == 2) { change++; goto q; }; break; case 'O': runner[0] = runner[1] = runner[2] = false; break; } } q:; int m = 0; foreach (bool u in runner) if (u) m++; Console.WriteLine(j - 3 - m); if (change == a) break; } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication35 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); int change = 0; while (true) { int @out = 0, j = 0; bool[] runner = { false, false, false }; while (true) { string y = Console.ReadLine(); j++; switch (y[1]) { case 'I': runner[2] = runner[1]; runner[1] = runner[0]; runner[0] = true; break; case 'U': if (@out++ == 2) { change++; goto q; }; break; case 'O': runner[0] = runner[1] = runner[2] = false; break; } } q:; int m = 0; foreach (bool u in runner) if (u) m++; Console.WriteLine(j - 3 - m); if (change == a) break; } } } }
[["-", 0, 239, 0, 1, 0, 11, 12, 211, 0, 147], ["+", 0, 239, 0, 1, 0, 11, 12, 211, 0, 146]]
8
231
2
using System; using System.Collections.Generic; using System.Linq; namespace AOJ.Volume1 { public class BookIndex { public static void Main() { var index = new Dictionary<string, List<int>>(); while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } var line = Console.ReadLine().Split(' '); if (index.ContainsKey(line[0])) { index[line[0]].Add(int.Parse(line[1])); } else { index.Add(line[0], new List<int> { int.Parse(line[1]) }); } } foreach (var i in index.OrderBy(x => x.Key)) { Console.WriteLine(i.Key); string pages = ""; foreach (var p in i.Value.OrderBy(x => x)) { pages += p + " "; } pages = pages.Trim(); Console.WriteLine(pages); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AOJ.Volume1 { public class BookIndex { public static void Main() { var index = new Dictionary<string, List<int>>(); while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } var line = input.Split(' '); if (index.ContainsKey(line[0])) { index[line[0]].Add(int.Parse(line[1])); } else { index.Add(line[0], new List<int> { int.Parse(line[1]) }); } } foreach (var i in index.OrderBy(x => x.Key)) { Console.WriteLine(i.Key); string pages = ""; foreach (var p in i.Value.OrderBy(x => x)) { pages += p + " "; } pages = pages.Trim(); Console.WriteLine(pages); } } } }
[["-", 0, 213, 63, 214, 205, 213, 63, 214, 205, 22], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 0, 131], ["-", 0, 213, 63, 214, 205, 213, 63, 214, 141, 22], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 24], ["-", 0, 213, 63, 214, 205, 213, 3, 4, 0, 25], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22]]
8
233
6
using System; using System.Linq; namespace V0105 { public class Program { public static void Main(string[] args) { var sr = new StreamReader(); //--------------------------------- sr.Next<string>(100, 2) .TakeWhile(s => s[0] != "") .GroupBy(s => s[0]) .OrderBy(g => g.Key) .ToList() .ForEach(g => { Console.WriteLine(g.Key); Console.WriteLine(string.Join(" ", g.Select(s => int.Parse(s[1])) .OrderBy(s => s) .Select(x => x.ToString()) .ToArray())); }); //--------------------------------- } } public class StreamReader { private readonly char[] _c = { ' ' }; private int _index = -1; private string[] _input = new string[0]; public T Next<T>() { if (_index == _input.Length - 1) { _index = -1; while (true) { string rl = Console.ReadLine(); if (rl == null) { if (typeof(T).IsClass) return default(T); return (T) typeof(T).GetField("MinValue").GetValue(null); } if (rl != "") { _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType( _input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } public T[] Next<T>(int x) { var result = new T[x]; for (var i = 0; i < x; ++i) result[i] = Next<T>(); return result; } public T[][] Next<T>(int y, int x) { var result = new T[y][]; for (var i = 0; i < y; ++i) result[i] = Next<T>(x); return result; } } }
using System; using System.Linq; namespace V0105 { public class Program { public static void Main(string[] args) { var sr = new StreamReader(); //--------------------------------- sr.Next<string>(100, 2) .TakeWhile(s => s[0] != null) .GroupBy(s => s[0]) .OrderBy(g => g.Key) .ToList() .ForEach(g => { Console.WriteLine(g.Key); Console.WriteLine(string.Join(" ", g.Select(s => int.Parse(s[1])) .OrderBy(s => s) .Select(x => x.ToString()) .ToArray())); }); //--------------------------------- } } public class StreamReader { private readonly char[] _c = { ' ' }; private int _index = -1; private string[] _input = new string[0]; public T Next<T>() { if (_index == _input.Length - 1) { _index = -1; while (true) { string rl = Console.ReadLine(); if (rl == null) { if (typeof(T).IsClass) return default(T); return (T) typeof(T).GetField("MinValue").GetValue(null); } if (rl != "") { _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType( _input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } public T[] Next<T>(int x) { var result = new T[x]; for (var i = 0; i < x; ++i) result[i] = Next<T>(); return result; } public T[][] Next<T>(int y, int x) { var result = new T[y][]; for (var i = 0; i < y; ++i) result[i] = Next<T>(x); return result; } } }
[["-", 0, 28, 0, 218, 8, 16, 12, 5, 0, 62], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 12, 215]]
8
444
3
using System; using System.Collections.Generic; namespace AOJ.Volume1 { public class MilkShop { public static void Main() { while (true) { int cust_num = int.Parse(Console.ReadLine()); if (cust_num == 0) { break; } var wait_time = new List<int>(); for (int i = 0; i < cust_num; i++) { wait_time.Add(int.Parse(Console.ReadLine())); } wait_time.Sort(); long ans = 0; long b = 0; for (int i = 0; i < wait_time.Count; i++) { b += ans; ans += wait_time[i]; } Console.WriteLine(ans); } } } }
using System; using System.Collections.Generic; namespace AOJ.Volume1 { public class MilkShop { public static void Main() { while (true) { int cust_num = int.Parse(Console.ReadLine()); if (cust_num == 0) { break; } var wait_time = new List<int>(); for (int i = 0; i < cust_num; i++) { wait_time.Add(int.Parse(Console.ReadLine())); } wait_time.Sort(); long ans = 0; long tmp = 0; for (int i = 0; i < wait_time.Count; i++) { ans += tmp; tmp += wait_time[i]; } Console.WriteLine(ans); } } } }
[["-", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["+", 8, 196, 0, 197, 0, 198, 0, 200, 141, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22], ["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 107], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 11, 31, 22]]
8
154
8
using System; using System.Linq; namespace Aizu { class OnlineJudge { public static void Main() { for (int t, f = 0; (t = int.Parse(Console.ReadLine())) != 0; f = 1) { if (f != 0) { Console.WriteLine(); } var items = Enumerable.Range(0, t) .Select(q => { var i = Console.ReadLine().Split(); return new { n = i[0], i = q, p = int.Parse(i[1]) * 3 + int.Parse(i[3]) }; }) .OrderByDescending(q => q.p) .ThenByDescending(q => q.n); foreach (var item in items) { Console.WriteLine("{0},{1}", item.n, item.p); } } } } }
using System; using System.Linq; namespace Aizu { class OnlineJudge { public static void Main() { for (int t, f = 0; (t = int.Parse(Console.ReadLine())) != 0; f = 1) { if (f != 0) { Console.WriteLine(); } var items = Enumerable.Range(0, t) .Select(q => { var i = Console.ReadLine().Split(); return new { n = i[0], i = q, p = int.Parse(i[1]) * 3 + int.Parse(i[3]) }; }) .OrderByDescending(q => q.p) .ThenBy(q => q.i); foreach (var item in items) { Console.WriteLine("{0},{1}", item.n, item.p); } } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 141, 22], ["-", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22], ["+", 3, 4, 0, 28, 0, 218, 8, 214, 141, 22]]
8
186
4
using System; using System.Collections.Generic; namespace AOJ.Volume1 { public class PocketPagerInput { public static void Main() { var dic = new Dictionary<string, string> { { "11", "a" }, { "12", "b" }, { "13", "c" }, { "14", "d" }, { "15", "e" }, { "21", "f" }, { "22", "g" }, { "23", "h" }, { "24", "i" }, { "25", "j" }, { "31", "k" }, { "32", "l" }, { "33", "m" }, { "34", "n" }, { "35", "o" }, { "41", "p" }, { "42", "q" }, { "43", "r" }, { "44", "s" }, { "45", "t" }, { "51", "u" }, { "52", "v" }, { "53", "w" }, { "54", "x" }, { "55", "y" }, { "61", "z" }, { "62", "." }, { "63", "?" }, { "64", "!" }, { "65", " " } }; while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } string answer = ""; // 文字数が偶数でない場合は変換できない if (input.Length % 2 != 0) { Console.WriteLine("NA"); continue; } // 使用している文字が正しいか var check = answer.ToCharArray(); int cnt = 1; bool enable = true; foreach (var c in check) { // 奇数番目の文字は"1"?"6" // 偶数番目の文字は"1"?"5" char to_char = cnt % 2 == 0 ? '5' : '6'; if (c < '1' || c > to_char) { enable = false; break; } cnt++; } if (!enable) { Console.WriteLine("NA"); continue; } for (int i = 0; i < input.Length; i = i + 2) { answer += dic[input.Substring(i, 2)]; } Console.WriteLine(answer); } } } }
using System; using System.Collections.Generic; namespace AOJ.Volume1 { public class PocketPagerInput { public static void Main() { var dic = new Dictionary<string, string> { { "11", "a" }, { "12", "b" }, { "13", "c" }, { "14", "d" }, { "15", "e" }, { "21", "f" }, { "22", "g" }, { "23", "h" }, { "24", "i" }, { "25", "j" }, { "31", "k" }, { "32", "l" }, { "33", "m" }, { "34", "n" }, { "35", "o" }, { "41", "p" }, { "42", "q" }, { "43", "r" }, { "44", "s" }, { "45", "t" }, { "51", "u" }, { "52", "v" }, { "53", "w" }, { "54", "x" }, { "55", "y" }, { "61", "z" }, { "62", "." }, { "63", "?" }, { "64", "!" }, { "65", " " } }; while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } string answer = ""; // 文字数が偶数でない場合は変換できない if (input.Length % 2 != 0) { Console.WriteLine("NA"); continue; } // 使用している文字が正しいか var check = input.ToCharArray(); int cnt = 1; bool enable = true; foreach (var c in check) { // 奇数番目の文字は"1"?"6" // 偶数番目の文字は"1"?"5" char to_char = cnt % 2 == 0 ? '5' : '6'; if (c < '1' || c > to_char) { enable = false; break; } cnt++; } if (!enable) { Console.WriteLine("NA"); continue; } for (int i = 0; i < input.Length; i = i + 2) { answer += dic[input.Substring(i, 2)]; } Console.WriteLine(answer); } } } }
[["-", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22], ["+", 0, 200, 0, 212, 0, 213, 63, 214, 205, 22]]
8
530
2
using System; namespace AOJ.Volume1 { public class Train { public static int Main() { int cnt = int.Parse(Console.ReadLine()); for (int c = 0; c < cnt; c++) { string input = Console.ReadLine(); // 列車の初期化 string answer = input.Substring(0, 1); while (input.IndexOf("->") < 0 && input.IndexOf("<-") < 0) { string move = input.Substring(1, 2); string before = input.Substring(0, 1); string after = input.Substring(3, 1); // 前の車両に移動する場合(a->b)→"a"が最後尾なら文字列の最後に"b"を追加 // 後ろの車両に移動する場合(a<-b)→"a"が先頭なら文字列の先頭に"b"を追加 if (move == "->") { if (answer.IndexOf(before) == answer.Length - 1) { answer += after; } } else { if (answer.IndexOf(before) == 0) { answer = after + answer; } } input = input.Substring(3); } Console.WriteLine(answer); } return 0; } } }
using System; namespace AOJ.Volume1 { public class Train { public static int Main() { int cnt = int.Parse(Console.ReadLine()); for (int c = 0; c < cnt; c++) { string input = Console.ReadLine(); // 列車の初期化 string answer = input.Substring(0, 1); while (input.IndexOf("->") > 0 || input.IndexOf("<-") > 0) { string move = input.Substring(1, 2); string before = input.Substring(0, 1); string after = input.Substring(3, 1); // 前の車両に移動する場合(a->b)→"a"が最後尾なら文字列の最後に"b"を追加 // 後ろの車両に移動する場合(a<-b)→"a"が先頭なら文字列の先頭に"b"を追加 if (move == "->") { if (answer.IndexOf(before) == answer.Length - 1) { answer += after; } } else { if (answer.IndexOf(before) == 0) { answer = after + answer; } } input = input.Substring(3); } Console.WriteLine(answer); } return 0; } } }
[["-", 8, 196, 0, 52, 15, 16, 31, 16, 17, 18], ["+", 8, 196, 0, 52, 15, 16, 31, 16, 17, 47], ["-", 0, 7, 8, 196, 0, 52, 15, 16, 17, 98], ["+", 0, 7, 8, 196, 0, 52, 15, 16, 17, 106], ["-", 8, 196, 0, 52, 15, 16, 12, 16, 17, 18], ["+", 8, 196, 0, 52, 15, 16, 12, 16, 17, 47]]
8
210
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication32 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); double[] b = new double[a]; string d, e, f, g, h, i; d = e = f = g = h = i = ""; for (int c = 0; c < a; c++) { b[c] = int.Parse(Console.ReadLine()); if (b[c] < 165) d += "*"; if (b[c] <= 165 && b[c] < 170) e += "*"; if (b[c] <= 170 && b[c] < 175) f += "*"; if (b[c] <= 175 && b[c] < 180) h += "*"; if (b[c] <= 180 && b[c] < 185) i += "*"; if (b[c] <= 185) g += "*"; } Console.WriteLine("1:{0}", d); Console.WriteLine("2:{0}", e); Console.WriteLine("3:{0}", f); Console.WriteLine("4:{0}", h); Console.WriteLine("5:{0}", i); Console.WriteLine("6:{0}", g); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication32 { class Program { static void Main() { int a = int.Parse(Console.ReadLine()); double[] b = new double[a]; string d, e, f, g, h, i; d = e = f = g = h = i = ""; for (int c = 0; c < a; c++) { b[c] = double.Parse(Console.ReadLine()); if (b[c] < 165) d += "*"; if (b[c] >= 165 && b[c] < 170) e += "*"; if (b[c] >= 170 && b[c] < 175) f += "*"; if (b[c] >= 175 && b[c] < 180) h += "*"; if (b[c] >= 180 && b[c] < 185) i += "*"; if (b[c] >= 185) g += "*"; } Console.WriteLine("1:{0}", d); Console.WriteLine("2:{0}", e); Console.WriteLine("3:{0}", f); Console.WriteLine("4:{0}", h); Console.WriteLine("5:{0}", i); Console.WriteLine("6:{0}", g); } } }
[["-", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["+", 0, 1, 0, 11, 12, 213, 63, 214, 205, 199], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 19], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 17, 20], ["-", 0, 7, 8, 196, 0, 57, 15, 16, 17, 19], ["+", 0, 7, 8, 196, 0, 57, 15, 16, 17, 20]]
8
304
12
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Train { class Class2 { const string mark = "*"; static void Main(string[] args) { new Class2().solve(); } void solve() { int size_Data = int.Parse(Console.ReadLine()); string[] result = new string[6]; for (int i = 0; i < size_Data; i++) { double data = double.Parse(Console.ReadLine()); if (data < 165.0) { result[0] += mark; } else if (data >= 165.0 && data < 170.0) { result[1] += mark; } else if (data >= 170.0 && data < 175.0) { result[2] += mark; } else if (data >= 175.0 && data < 180.0) { result[3] += mark; } else if (data >= 180.0 && data < 185.0) { result[4] += mark; } else { result[5] += mark; } } for (int i = 0; i < result.Length; i++) { Console.WriteLine(i + ":" + result[i]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Train { class Class2 { const string mark = "*"; static void Main(string[] args) { new Class2().solve(); } void solve() { int size_Data = int.Parse(Console.ReadLine()); string[] result = new string[6]; for (int i = 0; i < size_Data; i++) { double data = double.Parse(Console.ReadLine()); if (data < 165.0) { result[0] += mark; } else if (data >= 165.0 && data < 170.0) { result[1] += mark; } else if (data >= 170.0 && data < 175.0) { result[2] += mark; } else if (data >= 175.0 && data < 180.0) { result[3] += mark; } else if (data >= 180.0 && data < 185.0) { result[4] += mark; } else { result[5] += mark; } } for (int i = 0; i < result.Length; i++) { Console.WriteLine((i + 1) + ":" + result[i]); } } } }
[["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 203], ["+", 0, 28, 0, 16, 31, 16, 31, 23, 0, 25]]
8
256
4
using System; namespace AOJ.Volume1 { public class CandyAndClassFlag { public static int Main() { while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } int candy = int.Parse(input); // キャンディーを39で割った余りが出席番号 // ※余りが0の場合は出席番号39 int ans = candy % 39; if (ans == 0) { ans = 39; } Console.WriteLine(string.Format("3C{0}", ans)); } return 0; } } }
using System; namespace AOJ.Volume1 { public class CandyAndClassFlag { public static int Main() { while (true) { string input = Console.ReadLine(); if (string.IsNullOrEmpty(input)) { break; } int candy = int.Parse(input); // キャンディーを39で割った余りが出席番号 // ※余りが0の場合は出席番号39 int ans = candy % 39; if (ans == 0) { ans = 39; } Console.WriteLine(string.Format("3C{0:D2}", ans)); } return 0; } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
100
2
using System; class Program { static void Main() { var leftSight = new int[4]; var rightSight = new int[4]; for (string line; (line = Console.ReadLine()) != null;) { var l = line.Split(' '); var left = double.Parse(l[0]); var right = double.Parse(l[1]); leftSight[SightRank(left)]++; rightSight[SightRank(right)]++; } for (var i = 0; i < 4; i++) { Console.WriteLine(leftSight[i] + ' ' + rightSight[i]); } } static int SightRank(double sight) { if (sight >= 1.1) return 0; if (sight >= 0.6) return 1; if (sight >= 0.2) return 2; return 3; } }
using System; class Program { static void Main() { var leftSight = new int[4]; var rightSight = new int[4]; for (string line; (line = Console.ReadLine()) != null;) { var l = line.Split(' '); var left = double.Parse(l[0]); var right = double.Parse(l[1]); leftSight[SightRank(left)]++; rightSight[SightRank(right)]++; } for (var i = 0; i < 4; i++) { Console.WriteLine(leftSight[i] + " " + rightSight[i]); } } static int SightRank(double sight) { if (sight >= 1.1) return 0; if (sight >= 0.6) return 1; if (sight >= 0.2) return 2; return 3; } }
[["-", 0, 28, 0, 16, 31, 16, 12, 252, 0, 104], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62]]
8
182
4
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Myon { public Myon() {} public static int Main() { new Myon().run(); return 0; } int[] vy = new int[] { 1, 0, -1, 0 }; int[] vx = new int[] { 0, 1, 0, -1 }; int h, w; void run() { Scanner cin = new Scanner(); while (true) { w = cin.nextInt() + 2; h = cin.nextInt() + 2; int[,] flag = new int[h, w]; if (h == 2) break; for (int i = 0; i < h - 2; i++) { string s = Console.ReadLine(); for (int j = 0; j < w - 2; j++) { if (s[j] == '#') flag[i + 1, j + 1] = 1; else if (s[j] == '&') flag[i + 1, j + 1] = 2; } } Queue<int> now = new Queue<int>(); Queue<int> next = new Queue<int>(); int[,] dist = new int[h, w]; int MAX = 99999; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { dist[i, j] = MAX; } } now.Enqueue(0); dist[0, 0] = 0; int ret = MAX; while (ret == MAX) { while (now.Count != 0) { int nowp = now.Dequeue(); int y = nowp / w; int x = nowp % w; // Console.WriteLine("now: " + y + " " + x); for (int k = 0; k < 4; k++) { int ny = y + vy[k]; int nx = x + vx[k]; if (!ok(ny, nx)) continue; if (dist[ny, nx] != MAX) continue; if ((flag[ny, nx] ^ flag[y, x]) % 2 == 1) { dist[ny, nx] = dist[y, x] + 1; if (flag[ny, nx] == 2) ret = dist[ny, nx]; next.Enqueue(ny * w + nx); } else { dist[ny, nx] = dist[y, x]; if (flag[ny, nx] == 2) ret = dist[ny, nx]; now.Enqueue(ny * w + nx); } } } now = next; next = new Queue<int>(); } Console.WriteLine(ret); } } bool ok(int y, int x) { return y >= 0 && y < h && x >= 0 && x < w; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } }
using System; using System.Collections; using System.Collections.Generic; using System.Linq; class Myon { public Myon() {} public static int Main() { new Myon().run(); return 0; } int[] vy = new int[] { 1, 0, -1, 0 }; int[] vx = new int[] { 0, 1, 0, -1 }; int h, w; void run() { Scanner cin = new Scanner(); while (true) { w = cin.nextInt() + 2; h = cin.nextInt() + 2; int[,] flag = new int[h, w]; if (h == 2) break; for (int i = 0; i < h - 2; i++) { string s = Console.ReadLine(); for (int j = 0; j < w - 2; j++) { if (s[j] == '#') flag[i + 1, j + 1] = 1; else if (s[j] == '&') flag[i + 1, j + 1] = 2; } } Queue<int> now = new Queue<int>(); Queue<int> next = new Queue<int>(); int[,] dist = new int[h, w]; int MAX = 99999; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { dist[i, j] = MAX; } } now.Enqueue(0); dist[0, 0] = 0; int ret = MAX; while (ret == MAX) { while (now.Count != 0) { int nowp = now.Dequeue(); int y = nowp / w; int x = nowp % w; // Console.WriteLine("now: " + y + " " + x); for (int k = 0; k < 4; k++) { int ny = y + vy[k]; int nx = x + vx[k]; if (!ok(ny, nx)) continue; if (dist[ny, nx] != MAX) continue; if ((flag[ny, nx] ^ flag[y, x]) % 2 == 1) { dist[ny, nx] = dist[y, x] + 1; if (flag[ny, nx] == 2) ret = dist[ny, nx]; next.Enqueue(ny * w + nx); } else { dist[ny, nx] = dist[y, x]; if (flag[ny, nx] == 2) ret = dist[ny, nx]; now.Enqueue(ny * w + nx); } } } now = next; next = new Queue<int>(); } Console.WriteLine(ret / 2); } } bool ok(int y, int x) { return y >= 0 && y < h && x >= 0 && x < w; } } class Scanner { string[] s; int i; char[] cs = new char[] { ' ' }; public Scanner() { s = new string[0]; i = 0; } public string next() { if (i < s.Length) return s[i++]; s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries); i = 0; return s[i++]; } public int nextInt() { return int.Parse(next()); } public long nextLong() { return long.Parse(next()); } }
[["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 85], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 203]]
8
760
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static int ryoukin(int taiseki, int weight) { if (taiseki <= 60 && weight <= 2) { return 600; } if (taiseki <= 80 && weight <= 5) { return 800; } if (taiseki <= 100 && weight <= 10) { return 1000; } if (taiseki <= 120 && weight <= 15) { return 1200; } if (taiseki <= 140 && weight <= 20) { return 1400; } if (taiseki <= 160 && weight <= 25) { return 1600; } return 0; } public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } int sum = 0; for (int i = 0; i < n; i++) { line = Console.ReadLine(); string[] strs = line.Split(' '); int x = int.Parse(strs[0]), y = int.Parse(strs[1]), z = int.Parse(strs[2]), w = int.Parse(strs[3]); sum += ryoukin(x * y * z, w); } Console.WriteLine(sum); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static int ryoukin(int taiseki, int weight) { if (taiseki <= 60 && weight <= 2) { return 600; } if (taiseki <= 80 && weight <= 5) { return 800; } if (taiseki <= 100 && weight <= 10) { return 1000; } if (taiseki <= 120 && weight <= 15) { return 1200; } if (taiseki <= 140 && weight <= 20) { return 1400; } if (taiseki <= 160 && weight <= 25) { return 1600; } return 0; } public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } int sum = 0; for (int i = 0; i < n; i++) { line = Console.ReadLine(); string[] strs = line.Split(' '); int x = int.Parse(strs[0]), y = int.Parse(strs[1]), z = int.Parse(strs[2]), w = int.Parse(strs[3]); sum += ryoukin(x + y + z, w); } Console.WriteLine(sum); } } } }
[["-", 3, 4, 0, 28, 0, 16, 31, 16, 17, 48], ["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["-", 12, 213, 3, 4, 0, 28, 0, 16, 17, 48], ["+", 12, 213, 3, 4, 0, 28, 0, 16, 17, 72]]
8
297
4
using System; using System.Collections.Generic; using System.Linq; namespace AOJ.Volume1 { public class SportMeet { public static int Main() { while (true) { int team = int.Parse(Console.ReadLine()); if (team == 0) { break; } // チーム数が5の場合→0,1,2,3,4なので // ブービー賞は3 int booby = team - 2; var score = new List<KeyValuePair<int, int>>(); for (int i = 0; i < team; i++) { var input = Console.ReadLine().Split(' '); int id = int.Parse(input[0]); int time = int.Parse(input[1]) * 60 + int.Parse(input[2]) + int.Parse(input[3]) * 60 + int.Parse(input[4]) + int.Parse(input[5]) * 60 + int.Parse(input[6]) + int.Parse(input[7]) * 60 + int.Parse(input[8]); var kvp = new KeyValuePair<int, int>(id, time); score.Add(kvp); } int counter = 0; foreach (var s in score.OrderByDescending(x => x.Value)) { if (counter == 0 || counter == 1 || counter == booby) { Console.WriteLine(s.Key); } counter++; } } return 0; } } }
using System; using System.Collections.Generic; using System.Linq; namespace AOJ.Volume1 { public class SportMeet { public static int Main() { while (true) { int team = int.Parse(Console.ReadLine()); if (team == 0) { break; } // チーム数が5の場合→0,1,2,3,4なので // ブービー賞は3 int booby = team - 2; var score = new List<KeyValuePair<int, int>>(); for (int i = 0; i < team; i++) { var input = Console.ReadLine().Split(' '); int id = int.Parse(input[0]); int time = int.Parse(input[1]) * 60 + int.Parse(input[2]) + int.Parse(input[3]) * 60 + int.Parse(input[4]) + int.Parse(input[5]) * 60 + int.Parse(input[6]) + int.Parse(input[7]) * 60 + int.Parse(input[8]); var kvp = new KeyValuePair<int, int>(id, time); score.Add(kvp); } int counter = 0; foreach (var s in score.OrderBy(x => x.Value)) { if (counter == 0 || counter == 1 || counter == booby) { Console.WriteLine(s.Key); } counter++; } } return 0; } } }
[["-", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 210, 12, 213, 63, 214, 141, 22]]
8
302
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication11 { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { while (true) { int num_length = int.Parse(Console.ReadLine()); if (num_length == 0) { return; } int[] input = new int[num_length]; for (int i = 0; i < input.Length; i++) { input[i] = int.Parse(Console.ReadLine()); } int sorted = 0; int allsorted = 0; do { sorted = 0; for (int i = 0; i < input.Length - 1; i++) { int tmp = input[i]; if (input[i] > input[i + 1]) { input[i] = input[i + 1]; sorted++; } else break; input[i + 1] = tmp; } allsorted += sorted; } while (sorted > 0); Console.WriteLine(allsorted); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication11 { class Program { static void Main(string[] args) { new Program().solve(); } void solve() { while (true) { int num_length = int.Parse(Console.ReadLine()); if (num_length == 0) { return; } int[] input = new int[num_length]; for (int i = 0; i < input.Length; i++) { input[i] = int.Parse(Console.ReadLine()); } int sorted = 0; int allsorted = 0; do { sorted = 0; for (int i = 0; i < input.Length - 1; i++) { int tmp = input[i]; if (input[i] > input[i + 1]) { input[i] = input[i + 1]; sorted++; } else continue; input[i + 1] = tmp; } allsorted += sorted; } while (sorted > 0); Console.WriteLine(allsorted); } } } }
[["-", 0, 7, 8, 196, 0, 57, 75, 93, 0, 94], ["+", 0, 7, 8, 196, 0, 57, 75, 116, 0, 117]]
8
235
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { static int[] combinationTable = new int[31]; public static void Main(String[] args) { int dan; initTable(); while ((dan = int.Parse(Console.ReadLine())) != 0) { int num_combi = combinationTable[dan]; Console.WriteLine(1 + num_combi / 36500); } } public static void initTable() { combinationTable[0] = 1; combinationTable[1] = 1; combinationTable[2] = 2; combinationTable[3] = 4; for (int i = 4; i <= 30; i++) { combinationTable[i] = combinationTable[i - 1] + combinationTable[i - 2] + combinationTable[i - 3]; // Console.WriteLine(i + "," + combinationTable[i]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { static int[] combinationTable = new int[31]; public static void Main(String[] args) { int dan; initTable(); while ((dan = int.Parse(Console.ReadLine())) != 0) { int num_combi = combinationTable[dan]; Console.WriteLine(1 + num_combi / 3650); } } public static void initTable() { combinationTable[0] = 1; combinationTable[1] = 1; combinationTable[2] = 2; combinationTable[3] = 4; for (int i = 4; i <= 30; i++) { combinationTable[i] = combinationTable[i - 1] + combinationTable[i - 2] + combinationTable[i - 3]; // Console.WriteLine(i + "," + combinationTable[i]); } } } }
[["-", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203], ["+", 3, 4, 0, 28, 0, 16, 12, 16, 12, 203]]
8
178
2
using System; namespace _0184 { class Program { static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } int[] X = new int[7]; for (int i = 0; i < n; i++) { int now = int.Parse(Console.ReadLine()); if (now > 60) { X[6]++; } else { X[now / 10]++; } } for (int i = 0; i < 7; i++) { Console.WriteLine(X[i]); } Console.ReadLine(); } } } }
using System; namespace _0184 { class Program { static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } int[] X = new int[7]; for (int i = 0; i < n; i++) { int now = int.Parse(Console.ReadLine()); if (now > 60) { X[6]++; } else { X[now / 10]++; } } for (int i = 0; i < 7; i++) { Console.WriteLine(X[i]); } } } } }
[["-", 8, 196, 0, 1, 0, 213, 63, 214, 205, 22], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 0, 131], ["-", 8, 196, 0, 1, 0, 213, 63, 214, 141, 22], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 52, 8, 196, 0, 1, 0, 35]]
8
150
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0185 { public class Program { public static void Main(string[] args) { int[] primes = new int[1000001]; primes[2] = 1; for (int i = 3; i < 1000000; i += 2) { if (IsPrime(i)) primes[i] = 1; } while (true) { int n = RInt(); if (n == 0) break; int cnt = 0; for (int i = 0; primes[i] < n / 2 + 1; i++) { if (primes[i] == 1 && primes[n - i] == 1) cnt++; } Console.WriteLine(cnt); } } /// <summary> ///素数判定 /// </summary> public static bool IsPrime(long number) { long boundary = (long)Math.Floor(Math.Sqrt(number)); if (number == 1) return false; if (number == 2) return true; for (long i = 2; i <= boundary; ++i) { if (number % i == 0) return false; } return true; } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0185 { public class Program { public static void Main(string[] args) { int[] primes = new int[1000001]; primes[2] = 1; for (int i = 3; i < 1000000; i += 2) { if (IsPrime(i)) primes[i] = 1; } while (true) { int n = RInt(); if (n == 0) break; int cnt = 0; for (int i = 0; i < n / 2 + 1; i++) { if (primes[i] == 1 && primes[n - i] == 1) cnt++; } Console.WriteLine(cnt); } } /// <summary> ///素数判定 /// </summary> public static bool IsPrime(long number) { long boundary = (long)Math.Floor(Math.Sqrt(number)); if (number == 1) return false; if (number == 2) return true; for (long i = 2; i <= boundary; ++i) { if (number % i == 0) return false; } return true; } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
[["-", 8, 196, 0, 7, 15, 16, 31, 204, 205, 22], ["-", 0, 7, 15, 16, 31, 204, 206, 207, 0, 70], ["-", 0, 7, 15, 16, 31, 204, 206, 207, 0, 73]]
8
538
3
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0187 { public class Program { public const double EPS = 1e-10; public static void Main(string[] args) { while (true) { int[] ls1 = RIntAr(); if (ls1.Sum() == 0) break; int[] ls2 = RIntAr(); int[] ls3 = RIntAr(); double p1x, p1y, p2x, p2y, p3x, p3y; double slope1 = ls1[2] - ls1[0] == 0 ? int.MaxValue : (ls1[3] - ls1[1]) / (double)(ls1[2] - ls1[0]); double slope2 = ls2[2] - ls2[0] == 0 ? int.MaxValue : (ls2[3] - ls2[1]) / (double)(ls2[2] - ls2[0]); double slope3 = ls3[2] - ls3[0] == 0 ? int.MaxValue : (ls3[3] - ls3[1]) / (double)(ls3[2] - ls3[0]); if (Math.Abs(slope1 - slope2) < EPS || Math.Abs(slope2 - slope3) < EPS || Math.Abs(slope3 - slope1) < EPS) { Console.WriteLine("kyo"); continue; } bool isCross12 = Vector.IsLineSegmentCrossed(ls1[0], ls1[1], ls1[2], ls1[3], ls2[0], ls2[1], ls2[2], ls2[3], out p1x, out p1y); bool isCross23 = Vector.IsLineSegmentCrossed(ls2[0], ls2[1], ls2[2], ls2[3], ls3[0], ls3[1], ls3[2], ls3[3], out p2x, out p2y); bool isCross31 = Vector.IsLineSegmentCrossed(ls3[0], ls3[1], ls3[2], ls3[3], ls1[0], ls1[1], ls1[2], ls1[3], out p3x, out p3y); if (!isCross12 || !isCross23 || !isCross31) { Console.WriteLine("kyo"); } else { if ((Math.Abs(p1x - p2x) < EPS && Math.Abs(p1y - p2y) < EPS) || (Math.Abs(p2x - p3x) < EPS && Math.Abs(p2y - p3y) < EPS) || (Math.Abs(p3x - p1x) < EPS && Math.Abs(p3y - p1y) < EPS)) { Console.WriteLine("kyo"); } else { double area = CalcTriangleArea(p1x, p1y, p2x, p2y, p3x, p3y); if (area >= 1900000) Console.WriteLine("dai-kichi"); else if (area >= 1000000) Console.WriteLine("chu-kichi"); else if (area >= 100000) Console.WriteLine("kichi"); else if (area > 0) Console.WriteLine("syo-kichi"); else Console.WriteLine("kyo"); } } } } /// <summary> /// 3点に囲まれた三角形の面積を求める /// </summary> /// <param name="p1x">p1のx座標</param> /// <param name="p1y">p1のy座標</param> /// <param name="p2x">p2のx座標</param> /// <param name="p2y">p2のy座標</param> /// <param name="p3x">p3のx座標</param> /// <param name="p3y">p3のy座標</param> /// <returns>三角形の面積</returns> public static double CalcTriangleArea(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y) { return Math.Abs((p1x - p3x) * (p2y - p3y) - (p2x - p3x) * (p1y - p3y)) / 2.0; } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } public partial struct Vector : IFormattable { #region Internal Fields internal double _x; internal double _y; #endregion Internal Fields #region Public Properties public double X { get { return _x; } set { _x = value; } } public double Y { get { return _y; } set { _y = value; } } #endregion Public Properties #region Constructors public Vector(double x, double y) { _x = x; _y = y; } public Vector(double[] line) { _x = line[0]; _y = line[1]; } #endregion Constructors #region Public Methods public static bool operator ==(Vector vector1, Vector vector2) { return vector1.X == vector2.X && vector1.Y == vector2.Y; } public static bool operator !=(Vector vector1, Vector vector2) { return !(vector1 == vector2); } public static bool Equals(Vector vector1, Vector vector2) { return vector1.X.Equals(vector2.X) && vector1.Y.Equals(vector2.Y); } public override bool Equals(object o) { if ((null == o) || !(o is Vector)) return false; Vector value = (Vector)o; return Vector.Equals(this, value); } public bool Equals(Vector value) { return Vector.Equals(this, value); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } #endregion Public Methods #region Internal Properties public override string ToString() { return ConvertToString(null /* format string */, null /* format provider */); } public string ToString(IFormatProvider provider) { return ConvertToString(null /* format string */, provider); } string IFormattable.ToString(string format, IFormatProvider provider) { return ConvertToString(format, provider); } internal string ConvertToString(string format, IFormatProvider provider) { char separator = ' '; return String.Format(provider, "{1:" + format + "}{0}{2:" + format + "}", separator, _x, _y); } #endregion Internal Properties #region Public Methods public double Length { get { return Math.Sqrt(_x * _x + _y * _y); } } public double LengthSquared { get { return _x * _x + _y * _y; } } public void Normalize() { this /= Math.Max(Math.Abs(_x), Math.Abs(_y)); this /= Length; } public static double CrossProduct(Vector vector1, Vector vector2) { return vector1._x * vector2._y - vector1._y * vector2._x; } public static double AngleBetween(Vector vector1, Vector vector2) { double sin = vector1._x * vector2._y - vector2._x * vector1._y; double cos = vector1._x * vector2._x + vector1._y * vector2._y; return Math.Atan2(sin, cos) * (180 / Math.PI); } public static Vector Rotation(Vector v, double angle) { return Rotation(v, angle, new Vector(0, 0)); } public static Vector Rotation(Vector v, double angle, Vector basePoint) { double rad = angle * Math.PI / 180; Vector res = new Vector(); res.X = (v.X - basePoint.X) * Math.Cos(rad) - (v.Y - basePoint.Y) * Math.Sin(rad) + basePoint.X; res.Y = (v.X - basePoint.X) * Math.Sin(rad) + (v.Y - basePoint.Y) * Math.Cos(rad) + basePoint.Y; return res; } /// <summary> /// 線分ABと点Pの距離を求める /// </summary> /// <param name="sx">線分ABの始点x座標</param> /// <param name="sy">線分ABの始点y座標</param> /// <param name="ex">線分ABの終点x座標</param> /// <param name="ey">線分ABの終点y座標</param> /// <param name="px">地点Pのx座標</param> /// <param name="py">地点Pのy座標</param> /// <returns></returns> public static double RangeOfPointAndLineSegment(double sx, double sy, double ex, double ey, double px, double py) { Vector A = new Vector(sx, sy); Vector B = new Vector(ex, ey); Vector P = new Vector(px, py); return (P - CalcClosestPointOnLineSegment(A, B, P)).Length; } private static Vector CalcClosestPointOnLineSegment(Vector A, Vector B, Vector P) { Vector a = B - A; Vector b = P - A; double r = (a * b) / (a * a); if (r <= 0) return A; else if (r >= 1) return B; else return A + r * a; } /// <summary> /// 線分ABと線分CDの交差判定 /// </summary> /// <param name="ax">線分ABの始点x座標</param> /// <param name="ay">線分ABの始点y座標</param> /// <param name="bx">線分ABの終点x座標</param> /// <param name="by">線分ABの終点y座標</param> /// <param name="cx">線分CDの始点x座標</param> /// <param name="cy">線分CDの始点y座標</param> /// <param name="dx">線分CDの終点x座標</param> /// <param name="dy">線分CDの終点y座標</param> /// <param name="px">交点Pのx座標</param> /// <param name="py">交点Pのy座標</param> /// <returns></returns> public static bool IsLineSegmentCrossed(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, out double px, out double py) { Vector a = new Vector(ax, ay); Vector b = new Vector(bx, by); Vector c = new Vector(cx, cy); Vector d = new Vector(dx, dy); px = int.MinValue; py = int.MinValue; if ((CrossProduct(b - a, c - a) * CrossProduct(b - a, d - a) < 1e-10) && (CrossProduct(d - c, a - c) * CrossProduct(d - c, b - c) < 1e-10)) { Vector cd = d - c; double d1 = Math.Abs(CrossProduct(cd, a - c)); double d2 = Math.Abs(CrossProduct(cd, b - c)); double t = d1 / (d1 + d2); px = (a + (b - a) * t).X; py = (a + (b - a) * t).Y; return true; } else { return false; } } #endregion Public Methods #region Public Operators public static Vector operator -(Vector vector) { return new Vector(-vector._x, -vector._y); } public void Negate() { _x = -_x; _y = -_y; } public static Vector operator +(Vector vector1, Vector vector2) { return new Vector(vector1._x + vector2._x, vector1._y + vector2._y); } public static Vector Add(Vector vector1, Vector vector2) { return new Vector(vector1._x + vector2._x, vector1._y + vector2._y); } public static Vector operator -(Vector vector1, Vector vector2) { return new Vector(vector1._x - vector2._x, vector1._y - vector2._y); } public static Vector Subtract(Vector vector1, Vector vector2) { return new Vector(vector1._x - vector2._x, vector1._y - vector2._y); } public static Vector operator *(Vector vector, double scalar) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector Multiply(Vector vector, double scalar) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector operator *(double scalar, Vector vector) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector Multiply(double scalar, Vector vector) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector operator /(Vector vector, double scalar) { return vector * (1.0 / scalar); } public static Vector Divide(Vector vector, double scalar) { return vector * (1.0 / scalar); } public static double operator *(Vector vector1, Vector vector2) { return vector1._x * vector2._x + vector1._y * vector2._y; } public static double Multiply(Vector vector1, Vector vector2) { return vector1._x * vector2._x + vector1._y * vector2._y; } public static double Determinant(Vector vector1, Vector vector2) { return vector1._x * vector2._y - vector1._y * vector2._x; } #endregion Public Operators } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0187 { public class Program { public const double EPS = 1e-10; public static void Main(string[] args) { while (true) { int[] ls1 = RIntAr(); if (ls1.All(x => x == 0)) break; int[] ls2 = RIntAr(); int[] ls3 = RIntAr(); double p1x, p1y, p2x, p2y, p3x, p3y; double slope1 = ls1[2] - ls1[0] == 0 ? int.MaxValue : (ls1[3] - ls1[1]) / (double)(ls1[2] - ls1[0]); double slope2 = ls2[2] - ls2[0] == 0 ? int.MaxValue : (ls2[3] - ls2[1]) / (double)(ls2[2] - ls2[0]); double slope3 = ls3[2] - ls3[0] == 0 ? int.MaxValue : (ls3[3] - ls3[1]) / (double)(ls3[2] - ls3[0]); if (Math.Abs(slope1 - slope2) < EPS || Math.Abs(slope2 - slope3) < EPS || Math.Abs(slope3 - slope1) < EPS) { Console.WriteLine("kyo"); continue; } bool isCross12 = Vector.IsLineSegmentCrossed(ls1[0], ls1[1], ls1[2], ls1[3], ls2[0], ls2[1], ls2[2], ls2[3], out p1x, out p1y); bool isCross23 = Vector.IsLineSegmentCrossed(ls2[0], ls2[1], ls2[2], ls2[3], ls3[0], ls3[1], ls3[2], ls3[3], out p2x, out p2y); bool isCross31 = Vector.IsLineSegmentCrossed(ls3[0], ls3[1], ls3[2], ls3[3], ls1[0], ls1[1], ls1[2], ls1[3], out p3x, out p3y); if (!isCross12 || !isCross23 || !isCross31) { Console.WriteLine("kyo"); } else { if ((Math.Abs(p1x - p2x) < EPS && Math.Abs(p1y - p2y) < EPS) || (Math.Abs(p2x - p3x) < EPS && Math.Abs(p2y - p3y) < EPS) || (Math.Abs(p3x - p1x) < EPS && Math.Abs(p3y - p1y) < EPS)) { Console.WriteLine("kyo"); } else { double area = CalcTriangleArea(p1x, p1y, p2x, p2y, p3x, p3y); if (area >= 1900000) Console.WriteLine("dai-kichi"); else if (area >= 1000000) Console.WriteLine("chu-kichi"); else if (area >= 100000) Console.WriteLine("kichi"); else if (area > 0) Console.WriteLine("syo-kichi"); else Console.WriteLine("kyo"); } } } } /// <summary> /// 3点に囲まれた三角形の面積を求める /// </summary> /// <param name="p1x">p1のx座標</param> /// <param name="p1y">p1のy座標</param> /// <param name="p2x">p2のx座標</param> /// <param name="p2y">p2のy座標</param> /// <param name="p3x">p3のx座標</param> /// <param name="p3y">p3のy座標</param> /// <returns>三角形の面積</returns> public static double CalcTriangleArea(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y) { return Math.Abs((p1x - p3x) * (p2y - p3y) - (p2x - p3x) * (p1y - p3y)) / 2.0; } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } public partial struct Vector : IFormattable { #region Internal Fields internal double _x; internal double _y; #endregion Internal Fields #region Public Properties public double X { get { return _x; } set { _x = value; } } public double Y { get { return _y; } set { _y = value; } } #endregion Public Properties #region Constructors public Vector(double x, double y) { _x = x; _y = y; } public Vector(double[] line) { _x = line[0]; _y = line[1]; } #endregion Constructors #region Public Methods public static bool operator ==(Vector vector1, Vector vector2) { return vector1.X == vector2.X && vector1.Y == vector2.Y; } public static bool operator !=(Vector vector1, Vector vector2) { return !(vector1 == vector2); } public static bool Equals(Vector vector1, Vector vector2) { return vector1.X.Equals(vector2.X) && vector1.Y.Equals(vector2.Y); } public override bool Equals(object o) { if ((null == o) || !(o is Vector)) return false; Vector value = (Vector)o; return Vector.Equals(this, value); } public bool Equals(Vector value) { return Vector.Equals(this, value); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } #endregion Public Methods #region Internal Properties public override string ToString() { return ConvertToString(null /* format string */, null /* format provider */); } public string ToString(IFormatProvider provider) { return ConvertToString(null /* format string */, provider); } string IFormattable.ToString(string format, IFormatProvider provider) { return ConvertToString(format, provider); } internal string ConvertToString(string format, IFormatProvider provider) { char separator = ' '; return String.Format(provider, "{1:" + format + "}{0}{2:" + format + "}", separator, _x, _y); } #endregion Internal Properties #region Public Methods public double Length { get { return Math.Sqrt(_x * _x + _y * _y); } } public double LengthSquared { get { return _x * _x + _y * _y; } } public void Normalize() { this /= Math.Max(Math.Abs(_x), Math.Abs(_y)); this /= Length; } public static double CrossProduct(Vector vector1, Vector vector2) { return vector1._x * vector2._y - vector1._y * vector2._x; } public static double AngleBetween(Vector vector1, Vector vector2) { double sin = vector1._x * vector2._y - vector2._x * vector1._y; double cos = vector1._x * vector2._x + vector1._y * vector2._y; return Math.Atan2(sin, cos) * (180 / Math.PI); } public static Vector Rotation(Vector v, double angle) { return Rotation(v, angle, new Vector(0, 0)); } public static Vector Rotation(Vector v, double angle, Vector basePoint) { double rad = angle * Math.PI / 180; Vector res = new Vector(); res.X = (v.X - basePoint.X) * Math.Cos(rad) - (v.Y - basePoint.Y) * Math.Sin(rad) + basePoint.X; res.Y = (v.X - basePoint.X) * Math.Sin(rad) + (v.Y - basePoint.Y) * Math.Cos(rad) + basePoint.Y; return res; } /// <summary> /// 線分ABと点Pの距離を求める /// </summary> /// <param name="sx">線分ABの始点x座標</param> /// <param name="sy">線分ABの始点y座標</param> /// <param name="ex">線分ABの終点x座標</param> /// <param name="ey">線分ABの終点y座標</param> /// <param name="px">地点Pのx座標</param> /// <param name="py">地点Pのy座標</param> /// <returns></returns> public static double RangeOfPointAndLineSegment(double sx, double sy, double ex, double ey, double px, double py) { Vector A = new Vector(sx, sy); Vector B = new Vector(ex, ey); Vector P = new Vector(px, py); return (P - CalcClosestPointOnLineSegment(A, B, P)).Length; } private static Vector CalcClosestPointOnLineSegment(Vector A, Vector B, Vector P) { Vector a = B - A; Vector b = P - A; double r = (a * b) / (a * a); if (r <= 0) return A; else if (r >= 1) return B; else return A + r * a; } /// <summary> /// 線分ABと線分CDの交差判定 /// </summary> /// <param name="ax">線分ABの始点x座標</param> /// <param name="ay">線分ABの始点y座標</param> /// <param name="bx">線分ABの終点x座標</param> /// <param name="by">線分ABの終点y座標</param> /// <param name="cx">線分CDの始点x座標</param> /// <param name="cy">線分CDの始点y座標</param> /// <param name="dx">線分CDの終点x座標</param> /// <param name="dy">線分CDの終点y座標</param> /// <param name="px">交点Pのx座標</param> /// <param name="py">交点Pのy座標</param> /// <returns></returns> public static bool IsLineSegmentCrossed(double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy, out double px, out double py) { Vector a = new Vector(ax, ay); Vector b = new Vector(bx, by); Vector c = new Vector(cx, cy); Vector d = new Vector(dx, dy); px = int.MinValue; py = int.MinValue; if ((CrossProduct(b - a, c - a) * CrossProduct(b - a, d - a) < 1e-10) && (CrossProduct(d - c, a - c) * CrossProduct(d - c, b - c) < 1e-10)) { Vector cd = d - c; double d1 = Math.Abs(CrossProduct(cd, a - c)); double d2 = Math.Abs(CrossProduct(cd, b - c)); double t = d1 / (d1 + d2); px = (a + (b - a) * t).X; py = (a + (b - a) * t).Y; return true; } else { return false; } } #endregion Public Methods #region Public Operators public static Vector operator -(Vector vector) { return new Vector(-vector._x, -vector._y); } public void Negate() { _x = -_x; _y = -_y; } public static Vector operator +(Vector vector1, Vector vector2) { return new Vector(vector1._x + vector2._x, vector1._y + vector2._y); } public static Vector Add(Vector vector1, Vector vector2) { return new Vector(vector1._x + vector2._x, vector1._y + vector2._y); } public static Vector operator -(Vector vector1, Vector vector2) { return new Vector(vector1._x - vector2._x, vector1._y - vector2._y); } public static Vector Subtract(Vector vector1, Vector vector2) { return new Vector(vector1._x - vector2._x, vector1._y - vector2._y); } public static Vector operator *(Vector vector, double scalar) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector Multiply(Vector vector, double scalar) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector operator *(double scalar, Vector vector) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector Multiply(double scalar, Vector vector) { return new Vector(vector._x * scalar, vector._y * scalar); } public static Vector operator /(Vector vector, double scalar) { return vector * (1.0 / scalar); } public static Vector Divide(Vector vector, double scalar) { return vector * (1.0 / scalar); } public static double operator *(Vector vector1, Vector vector2) { return vector1._x * vector2._x + vector1._y * vector2._y; } public static double Multiply(Vector vector1, Vector vector2) { return vector1._x * vector2._x + vector1._y * vector2._y; } public static double Determinant(Vector vector1, Vector vector2) { return vector1._x * vector2._y - vector1._y * vector2._x; } #endregion Public Operators } }
[["-", 0, 57, 15, 16, 31, 213, 63, 214, 141, 22], ["+", 8, 196, 0, 57, 15, 213, 63, 214, 141, 22], ["-", 0, 57, 15, 16, 31, 213, 3, 4, 0, 25], ["+", 0, 28, 0, 218, 54, 219, 0, 220, 141, 22], ["+", 15, 213, 3, 4, 0, 28, 0, 218, 0, 221], ["+", 3, 4, 0, 28, 0, 218, 8, 16, 31, 22], ["+", 8, 196, 0, 57, 15, 213, 3, 4, 0, 25]]
8
2,609
7
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0188 { public class Program { public static void Main(string[] args) { while (true) { int n = RInt(); if (n == 0) break; int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = RInt(); } int target = RInt(); int cnt = 1; int left = 0; int right = n; while (right - left > 0) { cnt++; int mid = (left + right) / 2; if (nums[mid] == target) break; else if (nums[mid] < target) left = mid + 1; else right = mid - 1; } Console.WriteLine(cnt); } } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0188 { public class Program { public static void Main(string[] args) { while (true) { int n = RInt(); if (n == 0) break; int[] nums = new int[n]; for (int i = 0; i < n; i++) { nums[i] = RInt(); } int target = RInt(); int cnt = 0; int left = 0; int right = n - 1; while (right - left >= 0) { cnt++; int mid = (left + right) / 2; if (nums[mid] == target) break; else if (nums[mid] < target) left = mid + 1; else right = mid - 1; } Console.WriteLine(cnt); } } static string RSt() { return Console.ReadLine(); } static int RInt() { return int.Parse(Console.ReadLine().Trim()); } static long RLong() { return long.Parse(Console.ReadLine().Trim()); } static double RDouble() { return double.Parse(Console.ReadLine()); } static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); } static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); } static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); } static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); } static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); } } }
[["-", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 197, 0, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 17, 33], ["+", 0, 198, 0, 200, 0, 212, 0, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 52, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 52, 15, 16, 17, 20]]
8
477
6
using System; using System.Linq; namespace _0195 { class Program { static void Main(string[] args) { while (true) { int[] shop = new int[5]; int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == 0 && x[1] == 0) { break; } shop[0] = x[0] + x[1]; for (int i = 1; i < 4; i++) { int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray(); shop[i] = y[0] + y[1]; } if (shop[0] > shop[1] && shop[0] > shop[2] && shop[0] > shop[3] && shop[0] > shop[4]) { Console.WriteLine("A " + shop[0]); } else if (shop[1] > shop[2] && shop[1] > shop[3] && shop[1] > shop[4]) { Console.WriteLine("B " + shop[1]); } else if (shop[2] > shop[3] && shop[2] > shop[4]) { Console.WriteLine("C " + shop[2]); } else if (shop[3] > shop[4]) { Console.WriteLine("D " + shop[3]); } else { Console.WriteLine("E " + shop[4]); } } } } }
using System; using System.Linq; namespace _0195 { class Program { static void Main(string[] args) { while (true) { int[] shop = new int[5]; int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray(); if (x[0] == 0 && x[1] == 0) { break; } shop[0] = x[0] + x[1]; for (int i = 1; i < 5; i++) { int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray(); shop[i] = y[0] + y[1]; } if (shop[0] > shop[1] && shop[0] > shop[2] && shop[0] > shop[3] && shop[0] > shop[4]) { Console.WriteLine("A " + shop[0]); } else if (shop[1] > shop[2] && shop[1] > shop[3] && shop[1] > shop[4]) { Console.WriteLine("B " + shop[1]); } else if (shop[2] > shop[3] && shop[2] > shop[4]) { Console.WriteLine("C " + shop[2]); } else if (shop[3] > shop[4]) { Console.WriteLine("D " + shop[3]); } else { Console.WriteLine("E " + shop[4]); } } } } }
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 203]]
8
354
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { string[] strs = line.Split(' '); int n0 = int.Parse(strs[0]); int n1 = int.Parse(strs[1]); if (n0 == 0 && n1 == 0) { break; } int[] xy = new int[2]; xy[0] = Math.Max(n0, n1); xy[1] = Math.Min(n0, n1); int cnt = 0; while (true) { int resi = xy[0] % xy[1]; xy[0] = xy[1]; xy[1] = resi; cnt++; if (xy[1] == 0) { break; } } Console.WriteLine(xy[0] + " " + xy[1]); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { string[] strs = line.Split(' '); int n0 = int.Parse(strs[0]); int n1 = int.Parse(strs[1]); if (n0 == 0 && n1 == 0) { break; } int[] xy = new int[2]; xy[0] = Math.Max(n0, n1); xy[1] = Math.Min(n0, n1); int cnt = 0; while (true) { int resi = xy[0] % xy[1]; xy[0] = xy[1]; xy[1] = resi; cnt++; if (xy[1] == 0) { break; } } Console.WriteLine(xy[0] + " " + cnt); } } } }
[["-", 3, 4, 0, 28, 0, 16, 12, 204, 205, 22], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 70], ["-", 0, 16, 12, 204, 206, 207, 0, 28, 0, 203], ["-", 0, 28, 0, 16, 12, 204, 206, 207, 0, 73], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
228
5
using System.Collections.Generic; using System.Linq; using System; public class C { public const int INF = 99999; public const int MINF = -99999; } public class Hello { public static void Main() { while (true) { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); if (n == 0 && m == 0) break; var s = new int[n]; for (int i = 0; i < m; i++) { var x = Console.ReadLine().Trim(); if (x == "A") doA(s, n, 1); else if (x == "B") doB(s, n, 2); else if (x == "C") doC(s, n, 3); else doD(s, n, 4); } display(s); } } public static void display(int[] s) { foreach (var x in s) if (x == 1) Console.Write("A"); else if (x == 2) Console.Write("B"); else if (x == 3) Console.Write("C"); else if (x == 4) Console.Write("D"); else Console.Write("#"); Console.WriteLine(); } public static void doA(int[] s, int n, int A) { for (int i = 0; i < n; i++) if (s[i] == 0) { s[i] = A; break; } } public static void doB(int[] s, int n, int B) { if (n == 1) { s[0] = B; return; } if (n - 2 >= 0 && s[n - 1] == 0 && s[n - 2] != 1) { s[n - 1] = B; return; } for (int i = n - 2; i >= 1; i--) if (s[i] == 0 && s[i + 1] != 1 && s[i - 1] != 1) { s[i] = B; return; } if (s[0] == 0 && s[1] != 1) { s[0] = B; return; } doA(s, n, B); } public static void doC(int[] s, int n, int C) { if (n == 1) { s[0] = C; return; } if (s.Sum() == 0) { if (n % 2 == 0) s[n / 2 + 1] = C; else s[(n + 1) / 2] = C; return; } for (int i = 0; i < n; i++) { if (s[i] != 0 && (i + 1 < n) && s[i + 1] == 0) { s[i + 1] = C; return; } else if (s[i] != 0 && (i - 1 >= 0) && s[i - 1] == 0) { s[i - 1] = C; return; } } } public static void doD(int[] s, int n, int D) { if (s.Sum() == 0) { s[0] = D; return; } var abc = new List<int>(); if (s[0] == 0) abc.Add(C.MINF); else abc.Add(0); for (int i = 1; i < n - 1; i++) if (s[i] != 0) abc.Add(i); if (s[n - 1] == 0) abc.Add(C.INF); else abc.Add(n - 1); var maxp = -1; var wL = 0; var maxL = -1; for (int i = 1; i < abc.Count(); i++) { var t = (abc[i] + abc[i - 1]) / 2; if (t < 0) { maxp = 0; maxL = abc[i] - 1; } else if (t > n - 1) { wL = n - 2 - abc[i - 1]; if (wL > maxL) { maxL = wL; maxp = n - 1; } } else { if (t == i - 1) continue; wL = t - abc[i - 1] - 1; if (wL > maxL) { maxL = wL; maxp = t; } } } s[maxp] = D; } }
using System.Collections.Generic; using System.Linq; using System; public class C { public const int INF = 99999; public const int MINF = -99999; } public class Hello { public static void Main() { while (true) { string[] line = Console.ReadLine().Trim().Split(' '); var n = int.Parse(line[0]); var m = int.Parse(line[1]); if (n == 0 && m == 0) break; var s = new int[n]; for (int i = 0; i < m; i++) { var x = Console.ReadLine().Trim(); if (x == "A") doA(s, n, 1); else if (x == "B") doB(s, n, 2); else if (x == "C") doC(s, n, 3); else doD(s, n, 4); } display(s); } } public static void display(int[] s) { foreach (var x in s) if (x == 1) Console.Write("A"); else if (x == 2) Console.Write("B"); else if (x == 3) Console.Write("C"); else if (x == 4) Console.Write("D"); else Console.Write("#"); Console.WriteLine(); } public static void doA(int[] s, int n, int A) { for (int i = 0; i < n; i++) if (s[i] == 0) { s[i] = A; break; } } public static void doB(int[] s, int n, int B) { if (n == 1) { s[0] = B; return; } if (n - 2 >= 0 && s[n - 1] == 0 && s[n - 2] != 1) { s[n - 1] = B; return; } for (int i = n - 2; i >= 1; i--) if (s[i] == 0 && s[i + 1] != 1 && s[i - 1] != 1) { s[i] = B; return; } if (s[0] == 0 && s[1] != 1) { s[0] = B; return; } doA(s, n, B); } public static void doC(int[] s, int n, int C) { if (n == 1) { s[0] = C; return; } if (s.Sum() == 0) { if (n % 2 == 0) s[n / 2] = C; else s[(n + 1) / 2 - 1] = C; return; } for (int i = 0; i < n; i++) { if (s[i] != 0 && (i + 1 < n) && s[i + 1] == 0) { s[i + 1] = C; return; } else if (s[i] != 0 && (i - 1 >= 0) && s[i - 1] == 0) { s[i - 1] = C; return; } } } public static void doD(int[] s, int n, int D) { if (s.Sum() == 0) { s[0] = D; return; } var abc = new List<int>(); if (s[0] == 0) abc.Add(C.MINF); else abc.Add(0); for (int i = 1; i < n - 1; i++) if (s[i] != 0) abc.Add(i); if (s[n - 1] == 0) abc.Add(C.INF); else abc.Add(n - 1); var maxp = -1; var wL = 0; var maxL = -1; for (int i = 1; i < abc.Count(); i++) { var t = (abc[i] + abc[i - 1]) / 2; if (t < 0) { maxp = 0; maxL = abc[i] - 1; } else if (t > n - 1) { wL = n - 2 - abc[i - 1]; if (wL > maxL) { maxL = wL; maxp = n - 1; } } else { if (t == i - 1) continue; wL = t - abc[i - 1] - 1; if (wL > maxL) { maxL = wL; maxp = t; } } } s[maxp] = D; } }
[["-", 31, 204, 206, 207, 0, 28, 0, 16, 17, 72], ["-", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
1,017
4
using System; using System.Collections.Generic; using System.Linq; namespace AOJ { class Program { public static void Main(string[] args) { var pmax = 1000000; var primes = new bool[pmax + 1]; var maxsq = (int)Math.Sqrt(pmax); for (var i = 2; i <= pmax; i++) primes[i] = true; for (var i = 2; i <= maxsq; i++) if (primes[i]) for (var j = i * 2; j < pmax; j += i) primes[j] = false; List<int> num; while ((num = Console.ReadLine() .Split(' ') .Select(x => int.Parse(x)) .ToList())[0] > 0) { var menu = new List<int>(); var order = new bool[num[1] + 1]; var max = 0; for (var i = 0; i < num[0]; i++) menu.Add(int.Parse(Console.ReadLine())); order[0] = true; for (var i = 0; i < num[1]; i++) if (order[i]) { menu.ForEach(x => { if (i + x <= num[1]) order[i + x] = true; }); if (primes[i] && max < i) max = i; } Console.WriteLine(max < 1 ? "NA" : "{0}", max); } } } }
using System; using System.Collections.Generic; using System.Linq; namespace AOJ { class Program { public static void Main(string[] args) { var pmax = 1000000; var primes = new bool[pmax + 1]; var maxsq = (int)Math.Sqrt(pmax); for (var i = 2; i <= pmax; i++) primes[i] = true; for (var i = 2; i <= maxsq; i++) if (primes[i]) for (var j = i * 2; j < pmax; j += i) primes[j] = false; List<int> num; while ((num = Console.ReadLine() .Split(' ') .Select(x => int.Parse(x)) .ToList())[0] > 0) { var menu = new List<int>(); var order = new bool[num[1] + 1]; var max = 0; for (var i = 0; i < num[0]; i++) menu.Add(int.Parse(Console.ReadLine())); order[0] = true; for (var i = 0; i <= num[1]; i++) if (order[i]) { menu.ForEach(x => { if (i + x <= num[1]) order[i + x] = true; }); if (primes[i] && max < i) max = i; } Console.WriteLine(max < 1 ? "NA" : "{0}", max); } } } }
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19]]
8
338
2
using System; namespace AOJ { class AOJ0202 { static void Main(string[] args) { var ps = Prims(1000000); for (;;) { var line = Console.ReadLine().Split(); var n = int.Parse(line[0]); var m = int.Parse(line[1]); if (n == 0 && m == 0) break; var xs = new int[n]; for (var i = 0; i < n; i++) { xs[i] = int.Parse(Console.ReadLine()); } var ans = 0; var dp = new bool[m + 1]; dp[0] = true; for (var i = 0; i < n; i++) { for (var j = xs[i]; j <= m; j++) { if (dp[j - xs[i]]) { dp[j] = true; if (ps[j]) { ans = Math.Max(ans, j); } } } } Console.WriteLine(ans != 0 ? ans.ToString() : "NG"); } } static bool[] Prims(int n) { bool[] prims = new bool[n + 1]; for (var i = 2; i <= n; i++) prims[i] = true; for (var i = 2; i <= n; i++) { if (prims[i]) { for (var j = i + i; j <= n; j += i) prims[j] = false; } } return prims; } } }
using System; namespace AOJ { class AOJ0202 { static void Main(string[] args) { var ps = Prims(1000000); for (;;) { var line = Console.ReadLine().Split(); var n = int.Parse(line[0]); var m = int.Parse(line[1]); if (n == 0 && m == 0) break; var xs = new int[n]; for (var i = 0; i < n; i++) { xs[i] = int.Parse(Console.ReadLine()); } var ans = 0; var dp = new bool[m + 1]; dp[0] = true; for (var i = 0; i < n; i++) { for (var j = xs[i]; j <= m; j++) { if (dp[j - xs[i]]) { dp[j] = true; if (ps[j]) { ans = Math.Max(ans, j); } } } } Console.WriteLine(ans != 0 ? ans.ToString() : "NA"); } } static bool[] Prims(int n) { bool[] prims = new bool[n + 1]; for (var i = 2; i <= n; i++) prims[i] = true; for (var i = 2; i <= n; i++) { if (prims[i]) { for (var j = i + i; j <= n; j += i) prims[j] = false; } } return prims; } } }
[["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
344
2
using System; class Program { static void Main(string[] args) { // bool ehjejh = true; while (true) { int a = int.Parse(Console.ReadLine()); if (a == 0) { break; } string s = Convert.ToString((a), 8); s = s.Replace("7", "9"); s = s.Replace("6", "8"); s = s.Replace("5", "7"); s = s.Replace("4", "5"); Console.WriteLine(a); } } }
using System; class Program { static void Main(string[] args) { while (true) { int a = int.Parse(Console.ReadLine()); if (a == 0) { break; } string s = Convert.ToString((a), 8); s = s.Replace("7", "9"); s = s.Replace("6", "8"); s = s.Replace("5", "7"); s = s.Replace("4", "5"); Console.WriteLine(s); } } }
[["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["+", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22]]
8
130
2
using System; namespace _0209 { class Program { static int n, m; static int[,] w = new int[100, 100]; static int[,] p = new int[50, 50]; static int[,] p90 = new int[50, 50]; static int[,] p180 = new int[50, 50]; static int[,] p270 = new int[50, 50]; static void Main(string[] args) { while (ReadInput()) Solve(); } static void Solve() { for (int i = 0; i < n - m; i++) { for (int j = 0; j < n - m; j++) { int resX = 100, resY = 100; Match(i, j, p, ref resX, ref resY); Match(i, j, p90, ref resX, ref resY); Match(i, j, p180, ref resX, ref resY); Match(i, j, p270, ref resX, ref resY); if (resX != 100) { Console.WriteLine("{1} {0}", resX + 1, resY + 1); return; } } } Console.WriteLine("NA"); } static void Match(int x, int y, int[,] p, ref int resx, ref int resy) { int sx = -1, sy = -1; for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { var val = p[i, j]; if (val != -1) { if (sx == -1) { sx = x + i; sy = y + j; } if (val != w[x + i, y + j]) return; } } } if (sx < resx || (sx == resx && sy < resy)) { resx = sx; resy = sy; } } static bool ReadInput() { var strs = Console.ReadLine().Split(' '); n = int.Parse(strs[0]); m = int.Parse(strs[1]); if (n == 0 && m == 0) return false; for (int i = 0; i < n; i++) { strs = Console.ReadLine().Split(' '); for (int j = 0; j < n; j++) w[i, j] = int.Parse(strs[j]); } for (int i = 0; i < m; i++) { strs = Console.ReadLine().Split(' '); for (int j = 0, temp = 0; j < m; temp++) { try { var val = int.Parse(strs[temp].Trim()); var d = m - 1; p[i, j] = val; p90[-j + d, i] = val; p180[-i + d, -j + d] = val; p270[j, -i + d] = val; j++; } catch { } } } return true; } } }
using System; namespace _0209 { class Program { static int n, m; static int[,] w = new int[100, 100]; static int[,] p = new int[50, 50]; static int[,] p90 = new int[50, 50]; static int[,] p180 = new int[50, 50]; static int[,] p270 = new int[50, 50]; static void Main(string[] args) { while (ReadInput()) Solve(); } static void Solve() { for (int i = 0; i <= n - m; i++) { for (int j = 0; j <= n - m; j++) { int resX = 100, resY = 100; Match(i, j, p, ref resX, ref resY); Match(i, j, p90, ref resX, ref resY); Match(i, j, p180, ref resX, ref resY); Match(i, j, p270, ref resX, ref resY); if (resX != 100) { Console.WriteLine("{1} {0}", resX + 1, resY + 1); return; } } } Console.WriteLine("NA"); } static void Match(int x, int y, int[,] p, ref int resx, ref int resy) { int sx = -1, sy = -1; for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { var val = p[i, j]; if (val != -1) { if (sx == -1) { sx = x + i; sy = y + j; } if (val != w[x + i, y + j]) return; } } } if (sx < resx || (sx == resx && sy < resy)) { resx = sx; resy = sy; } } static bool ReadInput() { var strs = Console.ReadLine().Split(' '); n = int.Parse(strs[0]); m = int.Parse(strs[1]); if (n == 0 && m == 0) return false; for (int i = 0; i < n; i++) { strs = Console.ReadLine().Split(' '); for (int j = 0; j < n; j++) w[i, j] = int.Parse(strs[j]); } for (int i = 0; i < m; i++) { strs = Console.ReadLine().Split(' '); for (int j = 0, temp = 0; j < m; temp++) { try { var val = int.Parse(strs[temp].Trim()); var d = m - 1; p[i, j] = val; p90[-j + d, i] = val; p180[-i + d, -j + d] = val; p270[j, -i + d] = val; j++; } catch { } } } return true; } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["-", 0, 7, 8, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 7, 8, 196, 0, 7, 15, 16, 17, 19]]
8
670
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { static int sengetsu = 4280; static int kihon = 1150; public static void Main(String[] args) { int n; while ((n = int.Parse(Console.ReadLine())) != -1) { int ryokin = calc_ryokin(n); Console.WriteLine(sengetsu - ryokin); } } static int calc_ryokin(int water) { int ryokin = 0; if (water <= 10) { ryokin = kihon; } else if (water <= 20) { ryokin = kihon + (water - 10) * 125; } else if (water <= 30) { ryokin = kihon + (water - 20) * 140 + 125 * 10; } else if (water <= 40) { ryokin = kihon + (water - 30) * 160 + 140 * 10 + 125 * 10; } return ryokin; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { static int sengetsu = 4280; static int kihon = 1150; public static void Main(String[] args) { int n; while ((n = int.Parse(Console.ReadLine())) != -1) { int ryokin = calc_ryokin(n); Console.WriteLine(sengetsu - ryokin); } } static int calc_ryokin(int water) { int ryokin = 0; if (water <= 10) { ryokin = kihon; } else if (water <= 20) { ryokin = kihon + (water - 10) * 125; } else if (water <= 30) { ryokin = kihon + (water - 20) * 140 + 125 * 10; } else { ryokin = kihon + (water - 30) * 160 + 140 * 10 + 125 * 10; } return ryokin; } } }
[["-", 0, 57, 75, 57, 75, 57, 75, 57, 0, 121], ["-", 0, 57, 75, 57, 75, 57, 75, 57, 0, 24], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 31, 22], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 17, 19], ["-", 75, 57, 75, 57, 75, 57, 15, 16, 12, 203], ["-", 0, 57, 75, 57, 75, 57, 75, 57, 0, 25]]
8
198
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { while (true) { int a = int.Parse(Console.ReadLine()); if (a == -1) break; if (a < 11) Console.WriteLine(4280 - 1150); if (a < 21 && a > 10) Console.WriteLine(4280 - (1150 + (a - 10) * 125)); if (a < 31 && a > 20) Console.WriteLine(4280 - (2400 + (a - 20) * 140)); if (a < 41 && a > 30) Console.WriteLine(4280 - (3800 + (a - 30) * 160)); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication15 { class Program { static void Main(string[] args) { while (true) { int a = int.Parse(Console.ReadLine()); if (a == -1) break; if (a < 11) Console.WriteLine(4280 - 1150); if (a < 21 && a > 10) Console.WriteLine(4280 - (1150 + (a - 10) * 125)); if (a < 31 && a > 20) Console.WriteLine(4280 - (2400 + (a - 20) * 140)); if (a > 30) Console.WriteLine(4280 - (3800 + (a - 30) * 160)); } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 17, 18], ["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["-", 0, 52, 8, 196, 0, 57, 15, 16, 17, 98], ["-", 8, 196, 0, 57, 15, 16, 12, 16, 31, 22]]
8
170
4
using System; namespace _0216 { class Program { static void Main(string[] args) { int k = 4280; int y = 0; while (true) { int a = int.Parse(Console.ReadLine()); if (a == -1) { break; } if (a <= 10) { y = 1150; } else if (a <= 20) { y = 1150 + (a - 10) * 125; } else if (a <= 30) { y = 1250 + 1150 + (a - 20) * 140; } else // if (a <= 40) { y = 1400 + 1150 + 1250 + (a - 30) * 160; } } Console.WriteLine(y - k); } } }
using System; namespace _0216 { class Program { static void Main(string[] args) { int k = 4280; int y = 0; while (true) { int a = int.Parse(Console.ReadLine()); if (a == -1) { break; } if (a <= 10) { y = 1150; } else if (a <= 20) { y = 1150 + (a - 10) * 125; } else if (a <= 30) { y = 1250 + 1150 + (a - 20) * 140; } else // if (a <= 40) { y = 1400 + 1150 + 1250 + (a - 30) * 160; } Console.WriteLine(k - y); } } } }
[["-", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 31, 22], ["-", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 33], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22], ["+", 0, 195, 8, 196, 0, 52, 8, 196, 0, 46]]
8
148
6
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { int n; while ((n = int.Parse(Console.ReadLine())) != 0) { int max_dist = -1; int num_patient = -1; for (int i = 0; i < n; i++) { String[] strs = Console.ReadLine().Split(' '); int dist = int.Parse(strs[1]) + int.Parse(strs[2]); if (dist > max_dist) { max_dist = dist; num_patient = int.Parse(strs[0]); } } Console.WriteLine(num_patient); } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { public static void Main(String[] args) { int n; while ((n = int.Parse(Console.ReadLine())) != 0) { int max_dist = -1; int num_patient = -1; for (int i = 0; i < n; i++) { String[] strs = Console.ReadLine().Split(' '); int dist = int.Parse(strs[1]) + int.Parse(strs[2]); if (dist > max_dist) { max_dist = dist; num_patient = int.Parse(strs[0]); } } Console.WriteLine(num_patient + " " + max_dist); } } } }
[["+", 3, 4, 0, 28, 0, 16, 31, 16, 17, 72], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 62], ["+", 0, 28, 0, 16, 31, 16, 12, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 17, 72], ["+", 0, 213, 3, 4, 0, 28, 0, 16, 12, 22]]
8
164
6
using System; using System.Linq; namespace _0217 { class Program { static void Main(string[] args) { while (true) { int asd = Int32.Parse(Console.ReadLine()); if (asd == 0) { break; } int[] kanja = new int[asd]; int[] yobi = new int[asd * 2]; for (int i = 0; i < asd; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); kanja[i] = a[1] + a[2]; yobi[i * 2] = a[0]; yobi[i * 2 + 1] = kanja[i]; } Array.Sort(kanja); for (int i = 0; i < asd; i++) { if (kanja[i] == yobi[i * 2 + 1]) { Console.WriteLine(yobi[i * 2] + " " + yobi[i * 2 + 1]); break; } } } } } }
using System; using System.Linq; namespace _0217 { class Program { static void Main(string[] args) { while (true) { int asd = Int32.Parse(Console.ReadLine()); if (asd == 0) { break; } int[] kanja = new int[asd]; int[] yobi = new int[asd * 2]; for (int i = 0; i < asd; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); kanja[i] = a[1] + a[2]; yobi[i * 2] = a[0]; yobi[i * 2 + 1] = kanja[i]; } Array.Sort(kanja); for (int i = 0; i < asd; i++) { if (kanja[asd - 1] == yobi[i * 2 + 1]) { Console.WriteLine(yobi[i * 2] + " " + yobi[i * 2 + 1]); break; } } } } } }
[["-", 15, 16, 31, 204, 206, 207, 0, 28, 0, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 31, 22], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 17, 33], ["+", 31, 204, 206, 207, 0, 28, 0, 16, 12, 203]]
8
232
4
using System; using System.Linq; public class Program { public static void Main(string[] aksjdsk) { // code goes here while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } for (int i = 0; i < n; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if ((a[0] == 100 || a[1] == 100 || a[2] == 100) || (a[0] + a[1] >= 180) || (a[0] + a[1] + a[2] >= 240)) { Console.WriteLine("A"); continue; } if (a[0] + a[1] + a[2] >= 210) { Console.WriteLine("B"); continue; } if (a[0] + a[1] + a[2] >= 50 && (a[0] >= 80 || a[1] >= 80)) { Console.WriteLine("B"); } else { Console.WriteLine("C"); } } } } }
using System; using System.Linq; public class Program { public static void Main(string[] aksjdsk) { // code goes here while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } for (int i = 0; i < n; i++) { int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray(); if ((a[0] == 100 || a[1] == 100 || a[2] == 100) || (a[0] + a[1] >= 180) || (a[0] + a[1] + a[2] >= 240)) { Console.WriteLine("A"); continue; } if (a[0] + a[1] + a[2] >= 210) { Console.WriteLine("B"); continue; } if (a[0] + a[1] + a[2] >= 150 && (a[0] >= 80 || a[1] >= 80)) { Console.WriteLine("B"); } else { Console.WriteLine("C"); } } } } }
[["-", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203], ["+", 8, 196, 0, 57, 15, 16, 31, 16, 12, 203]]
8
259
2
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0219 { class Program { static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } int[] a = new int[9]; for (int i = 0; i < n; i++) { a[int.Parse(Console.ReadLine())]++; } for (int i = 0; i < n; i++) { if (a[i] == 0) { Console.Write("-"); Console.WriteLine(); continue; } for (int k = 0; k < a[i]; i++) { Console.Write("*"); } Console.WriteLine(); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _0219 { class Program { static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } int[] a = new int[10]; for (int i = 0; i < n; i++) { a[int.Parse(Console.ReadLine())]++; } for (int i = 0; i < a.Length; i++) { if (a[i] == 0) { Console.Write("-"); Console.WriteLine(); continue; } for (int k = 0; k < a[i]; k++) { Console.Write("*"); } Console.WriteLine(); } } } } }
[["-", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["+", 0, 212, 0, 227, 39, 224, 225, 226, 0, 203], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 205, 22], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 0, 131], ["+", 8, 196, 0, 7, 15, 16, 12, 214, 141, 22], ["-", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22], ["+", 0, 7, 8, 196, 0, 7, 26, 223, 0, 22]]
8
189
8
using System; using System.Collections.Generic; using System.Linq; using System.Text; using sc = Scanner; class Program { static void Main(string[] args) { var q = new AnswerCollecter<string>(); while (true) { int n, m; int[][] jem, move; int x, y; int count = 0; n = sc.NextInt(); jem = new int [n][]; if (n == 0) { q.Answer(); break; } for (int i = 0; i < n; i++) { jem[i] = sc.NextIntArray(); } m = sc.NextInt(); move = new int [m][]; for (int i = 0; i < m; i++) { move[i] = new int[2]; switch (sc.NextString()) { case "N": move[i][1] = sc.NextInt(); continue; case "E": move[i][0] = sc.NextInt(); continue; case "S": move[i][1] = -sc.NextInt(); continue; case "W": move[i][0] = -sc.NextInt(); continue; default: continue; } } x = y = 10; for (int i = 0; i < m; i++) { x += move[i][0]; y += move[i][1]; int xmax = Math.Max(x, x - move[i][0]); int xmin = Math.Min(x, x - move[i][0]); int ymax = Math.Max(y, y - move[i][1]); int ymin = Math.Min(y, y - move[i][1]); for (int j = 0; j < n; j++) { if ((xmax >= jem[j][0] && xmin <= jem[j][0]) && (ymax >= jem[j][1] && ymin <= jem[j][1])) { count++; jem[j][0] = -1; //重複して宝石を拾わないようにする jem[j][1] = -1; } } } q.Enqueue(count == n ? "YES" : "NO"); } q.Answer(); } } public class AnswerCollecter<T> { private Queue<T> q; public AnswerCollecter() { q = new Queue<T>(); } public void Enqueue(T item) { q.Enqueue(item); } public void Answer() { while (q.Count != 0) Console.WriteLine(q.Dequeue()); } } public static class Scanner { public static string NextString() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return tmp; } public static string[] NextStrArray() { return Console.ReadLine().Split(' '); } public static long[] NextLongArray() { string[] s = NextStrArray(); long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = long.Parse(s[i]); } return a; } public static int[] NextIntArray() { string[] s = NextStrArray(); int[] a = new int[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = int.Parse(s[i]); } return a; } public static int NextInt() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return int.Parse(tmp); } public static double NextDouble() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return double.Parse(tmp); } public static long NextLong() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return long.Parse(tmp); } public static double[] NextDoubleArray() { string[] s = NextStrArray(); double[] a = new double[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = double.Parse(s[i]); } return a; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using sc = Scanner; class Program { static void Main(string[] args) { var q = new AnswerCollecter<string>(); while (true) { int n, m; int[][] jem, move; int x, y; int count = 0; n = sc.NextInt(); jem = new int [n][]; if (n == 0) { q.Answer(); break; } for (int i = 0; i < n; i++) { jem[i] = sc.NextIntArray(); } m = sc.NextInt(); move = new int [m][]; for (int i = 0; i < m; i++) { move[i] = new int[2]; switch (sc.NextString()) { case "N": move[i][1] = sc.NextInt(); continue; case "E": move[i][0] = sc.NextInt(); continue; case "S": move[i][1] = -sc.NextInt(); continue; case "W": move[i][0] = -sc.NextInt(); continue; default: continue; } } x = y = 10; for (int i = 0; i < m; i++) { x += move[i][0]; y += move[i][1]; int xmax = Math.Max(x, x - move[i][0]); int xmin = Math.Min(x, x - move[i][0]); int ymax = Math.Max(y, y - move[i][1]); int ymin = Math.Min(y, y - move[i][1]); for (int j = 0; j < n; j++) { if ((xmax >= jem[j][0] && xmin <= jem[j][0]) && (ymax >= jem[j][1] && ymin <= jem[j][1])) { count++; jem[j][0] = -1; //重複して宝石を拾わないようにする jem[j][1] = -1; } } } q.Enqueue(count == n ? "Yes" : "No"); } q.Answer(); } } public class AnswerCollecter<T> { private Queue<T> q; public AnswerCollecter() { q = new Queue<T>(); } public void Enqueue(T item) { q.Enqueue(item); } public void Answer() { while (q.Count != 0) Console.WriteLine(q.Dequeue()); } } public static class Scanner { public static string NextString() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return tmp; } public static string[] NextStrArray() { return Console.ReadLine().Split(' '); } public static long[] NextLongArray() { string[] s = NextStrArray(); long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = long.Parse(s[i]); } return a; } public static int[] NextIntArray() { string[] s = NextStrArray(); int[] a = new int[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = int.Parse(s[i]); } return a; } public static int NextInt() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return int.Parse(tmp); } public static double NextDouble() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return double.Parse(tmp); } public static long NextLong() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return long.Parse(tmp); } public static double[] NextDoubleArray() { string[] s = NextStrArray(); double[] a = new double[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = double.Parse(s[i]); } return a; } }
[["-", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 64, 5, 0, 222], ["-", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222], ["+", 3, 4, 0, 28, 0, 41, 75, 5, 0, 222]]
8
1,072
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { static bool[,] remainJ = new bool[21, 21]; static int robX = 10, robY = 10; public static void roboMv(string dir, int n) { char ch = dir[0]; for (int i = 0; i < n; i++) { if (ch == 'N') { robY++; } else if (ch == 'W') { robX++; } else if (ch == 'S') { robY--; } else if (ch == 'E') { robX--; } if (remainJ[robY, robX]) { remainJ[robY, robX] = false; } } } public static bool takeAllJ() { for (int i = 0; i <= 20; i++) { for (int j = 0; j <= 20; j++) { if (remainJ[i, j]) { return false; } } } return true; } public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } remainJ = new bool[21, 21]; robX = 10; robY = 10; for (int i = 0; i < n; i++) { int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); remainJ[ints[1], ints[0]] = true; } int m = int.Parse(Console.ReadLine()); for (int i = 0; i < m; i++) { string[] strs = Console.ReadLine().Split(' '); roboMv(strs[0], int.Parse(strs[1])); } if (takeAllJ()) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test1 { class ClassMain { static bool[,] remainJ = new bool[21, 21]; static int robX = 10, robY = 10; public static void roboMv(string dir, int n) { char ch = dir[0]; for (int i = 0; i < n; i++) { if (ch == 'N') { robY++; } else if (ch == 'E') { robX++; } else if (ch == 'S') { robY--; } else if (ch == 'W') { robX--; } if (remainJ[robY, robX]) { remainJ[robY, robX] = false; } // Console.WriteLine(robX + "x y" + robY); } } public static bool takeAllJ() { for (int i = 0; i <= 20; i++) { for (int j = 0; j <= 20; j++) { if (remainJ[i, j]) { return false; } } } return true; } public static void Main(String[] args) { string line; while ((line = Console.ReadLine()) != null) { int n = int.Parse(line); if (n == 0) { break; } remainJ = new bool[21, 21]; robX = 10; robY = 10; for (int i = 0; i < n; i++) { int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); remainJ[ints[1], ints[0]] = true; } int m = int.Parse(Console.ReadLine()); for (int i = 0; i < m; i++) { string[] strs = Console.ReadLine().Split(' '); roboMv(strs[0], int.Parse(strs[1])); } if (takeAllJ()) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); } } } } }
[["-", 0, 57, 75, 57, 15, 16, 12, 252, 0, 253], ["+", 0, 57, 75, 57, 15, 16, 12, 252, 0, 253], ["-", 75, 57, 75, 57, 15, 16, 12, 252, 0, 253], ["+", 75, 57, 75, 57, 15, 16, 12, 252, 0, 253]]
8
446
4
using System; using System.Linq; namespace Make_Purse_Light { class Program { private static void Main(string[] args) { int n, k, i = 0, q, j; int[] m = new int[4], x = new int[4], y = new int[4], p = new int[] { 10, 50, 100, 500 }; while (true) { n = int.Parse(Console.ReadLine()); if (n == 0) { break; } if (i != 0) { Console.WriteLine(); } i++; k = 0; m = Console.ReadLine() .Trim() .Split(' ') .Select(o => int.Parse(o)) .ToArray(); for (j = 3; j >= 0; j--) { k += m[j] * p[j]; } q = k - n; for (j = 3; j >= 0; j--) { x[j] = q / p[j]; q -= x[j] * p[j]; y[j] = Math.Max(0, m[j] - x[j]); } for (j = 0; j < 4; j++) { if (y[j] != 0) { Console.WriteLine("%d %d\n", p[j], y[j]); } } } } } }
using System; using System.Linq; namespace Make_Purse_Light { class Program { private static void Main(string[] args) { int n, k, i = 0, q, j; int[] m = new int[4], x = new int[4], y = new int[4], p = new int[] { 10, 50, 100, 500 }; while (true) { n = int.Parse(Console.ReadLine()); if (n == 0) { break; } if (i != 0) { Console.WriteLine(); } i++; k = 0; m = Console.ReadLine() .Trim() .Split(' ') .Select(o => int.Parse(o)) .ToArray(); for (j = 3; j >= 0; j--) { k += m[j] * p[j]; } q = k - n; for (j = 3; j >= 0; j--) { x[j] = q / p[j]; q -= x[j] * p[j]; y[j] = Math.Max(0, m[j] - x[j]); } for (j = 0; j < 4; j++) { if (y[j] != 0) { Console.WriteLine("{0} {1}", p[j], y[j]); } } } } } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 44], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
309
3
using System; class P { static void Main(string[] args) { bool a = false; int b, c, d, e; int[] f, g = new int[4], h = new int[4], i = new int[] { 10, 50, 100, 500 }; while (true) { b = int.Parse(Console.ReadLine()); if (b == 0) { break; } if (!a) { a = !a; } else { Console.WriteLine(); } c = 0; f = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (e = 3; e >= 0; e--) { c += f[e] * i[e]; } d = c - b; for (e = 3; e >= 0; e--) { g[e] = d / i[e]; d -= d % i[e]; h[e] = f[e] - g[e]; } for (e = 0; e < 4; e++) { if (h[e] > 0) { Console.WriteLine("{0} {1}", i[e], h[e]); } } } } }
using System; class P { static void Main(string[] args) { bool a = false; int b, c, d, e; int[] f, g = new int[4], h = new int[4], i = new int[] { 10, 50, 100, 500 }; while (true) { b = int.Parse(Console.ReadLine()); if (b == 0) { break; } if (!a) { a = !a; } else { Console.WriteLine(); } c = 0; f = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); for (e = 3; e >= 0; e--) { c += f[e] * i[e]; } d = c - b; for (e = 3; e >= 0; e--) { g[e] = d / i[e]; d = d % i[e]; h[e] = f[e] - g[e]; } for (e = 0; e < 4; e++) { if (h[e] > 0) { Console.WriteLine("{0} {1}", i[e], h[e]); } } } } }
[["-", 8, 196, 0, 1, 0, 11, 0, 202, 0, 110], ["+", 8, 196, 0, 1, 0, 11, 0, 202, 0, 32]]
8
276
2
using System; class Program { static void Main(string[] args) { bool isFirst = true; int[] coins = new int[] { 10, 50, 100, 500 }; int bill, ownedMoney, changeMoney; int[] ownedCoins = new int[4], changeCoins = new int[4], paymentCoins = new int[4]; while (true) { bill = int.Parse(Console.ReadLine()); if (bill == 0) break; if (isFirst) { isFirst = false; } else { Console.WriteLine(); } ownedCoins = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); ownedMoney = 0; for (int i = 3; i >= 0; i--) ownedMoney += coins[i] * ownedCoins[i]; changeMoney = ownedMoney - bill; for (int i = 3; i >= 0; i--) { changeCoins[i] = changeMoney / coins[i]; changeMoney = changeMoney % coins[i]; paymentCoins[i] = ownedCoins[i] - changeCoins[i]; } for (int i = 0; i < 3; i++) if (paymentCoins[i] > 0) Console.WriteLine("{0} {1}", coins[i], paymentCoins[i]); } } }
using System; class Program { static void Main(string[] args) { bool isFirst = true; int[] coins = new int[] { 10, 50, 100, 500 }; int bill, ownedMoney, changeMoney; int[] ownedCoins = new int[4], changeCoins = new int[4], paymentCoins = new int[4]; while (true) { bill = int.Parse(Console.ReadLine()); if (bill == 0) break; if (isFirst) { isFirst = false; } else { Console.WriteLine(); } ownedCoins = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); ownedMoney = 0; for (int i = 3; i >= 0; i--) ownedMoney += coins[i] * ownedCoins[i]; changeMoney = ownedMoney - bill; for (int i = 3; i >= 0; i--) { changeCoins[i] = changeMoney / coins[i]; changeMoney = changeMoney % coins[i]; paymentCoins[i] = ownedCoins[i] - changeCoins[i]; } for (int i = 0; i < 4; i++) if (paymentCoins[i] > 0) Console.WriteLine("{0} {1}", coins[i], paymentCoins[i]); } } }
[["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 203], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 203]]
8
276
2
using System; class Program { static void Main(string[] args) { bool isFirst = true; int[] coins = new int[] { 10, 50, 100, 500 }; int range = coins.Length; int bill, ownedMoney, changeMoney; int[] ownedCoins = new int[range], changeCoins = new int[range], paymentCoins = new int[range]; while (true) { bill = int.Parse(Console.ReadLine()); if (bill == 0) break; if (isFirst) { isFirst = false; } else { Console.WriteLine(); } ownedCoins = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); ownedMoney = 0; for (int i = range; i > 0; i--) ownedMoney += coins[i] * ownedCoins[i]; changeMoney = ownedMoney - bill; for (int i = range; i > 0; i--) { changeCoins[i] = changeMoney / coins[i]; changeMoney = changeMoney % coins[i]; paymentCoins[i] = ownedCoins[i] - changeCoins[i]; } for (int i = 0; i < range; i++) if (paymentCoins[i] > 0) Console.WriteLine("{0} {1}", coins[i], paymentCoins[i]); } } }
using System; class Program { static void Main(string[] args) { bool isFirst = true; int[] coins = new int[] { 10, 50, 100, 500 }; int range = coins.Length; int bill, ownedMoney, changeMoney; int[] ownedCoins = new int[range], changeCoins = new int[range], paymentCoins = new int[range]; while (true) { bill = int.Parse(Console.ReadLine()); if (bill == 0) break; if (isFirst) { isFirst = false; } else { Console.WriteLine(); } ownedCoins = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse); ownedMoney = 0; for (int i = 3; i >= 0; i--) ownedMoney += coins[i] * ownedCoins[i]; changeMoney = ownedMoney - bill; for (int i = 3; i >= 0; i--) { changeCoins[i] = changeMoney / coins[i]; changeMoney = changeMoney % coins[i]; paymentCoins[i] = ownedCoins[i] - changeCoins[i]; } for (int i = 0; i <= 3; i++) if (paymentCoins[i] > 0) Console.WriteLine("{0} {1}", coins[i], paymentCoins[i]); } } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 22], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 47], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 20], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 17, 18], ["-", 0, 52, 8, 196, 0, 7, 15, 16, 12, 22], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 196, 0, 7, 15, 16, 12, 203]]
8
283
12
using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Linq; using System.Text; class Program { static bool[] used; static int[] cells; static int ans; static int[] nums; static void Main(string[] args) { while (true) { string[] s = Console.ReadLine().Split(' '); nums = new int[11]; used = new bool[11]; cells = new int[11]; for (int i = 0; i < 10; i++) { cells[i] = int.Parse(s[i]); } if (cells[0] == -1) break; for (int i = 0; i < 10; i++) { if (cells[i] != 0) { used[cells[i]] = true; nums[i] = cells[i]; } } ans = 0; permutation(10, 0); Console.WriteLine(ans); } } static void permutation(int n, int pos) { if (n == pos) { bool flag = true; int mod = (nums[0] + nums[1] + nums[2]) % nums[9]; for (int i = 0; i < 3; i++) { if ((nums[i * 3] + nums[i * 3 + 1] + nums[i * 3 + 2]) % nums[9] != mod) flag = false; } for (int i = 0; i < 3; i++) { if ((nums[i] + nums[i + 3] + nums[i + 6]) % nums[9] != mod) flag = false; } if ((nums[0] + nums[4] + nums[8]) % nums[9] != mod) flag = false; if ((nums[2] + nums[4] + nums[6]) % nums[9] != mod) flag = false; if (flag) ans++; return; } if (cells[pos] == 0) { for (int i = 0; i < 10; i++) { if (used[i]) continue; used[i] = true; nums[pos] = i; permutation(n, pos + 1); used[i] = false; } } else { permutation(n, pos + 1); } return; } }
using System; using System.Collections.Generic; using System.Text.RegularExpressions; using System.Linq; using System.Text; class Program { static bool[] used; static int[] cells; static int ans; static int[] nums; static void Main(string[] args) { while (true) { string[] s = Console.ReadLine().Split(' '); nums = new int[11]; used = new bool[11]; cells = new int[11]; for (int i = 0; i < 10; i++) { cells[i] = int.Parse(s[i]); } if (cells[0] == -1) break; for (int i = 0; i < 10; i++) { if (cells[i] != 0) { used[cells[i]] = true; nums[i] = cells[i]; } } ans = 0; permutation(10, 0); Console.WriteLine(ans); } } static void permutation(int n, int pos) { if (n == pos) { bool flag = true; int mod = (nums[0] + nums[1] + nums[2]) % nums[9]; for (int i = 0; i < 3; i++) { if ((nums[i * 3] + nums[i * 3 + 1] + nums[i * 3 + 2]) % nums[9] != mod) flag = false; } for (int i = 0; i < 3; i++) { if ((nums[i] + nums[i + 3] + nums[i + 6]) % nums[9] != mod) flag = false; } if ((nums[0] + nums[4] + nums[8]) % nums[9] != mod) flag = false; if ((nums[2] + nums[4] + nums[6]) % nums[9] != mod) flag = false; if (flag) ans++; return; } if (cells[pos] == 0) { for (int i = 1; i <= 10; i++) { if (used[i]) continue; used[i] = true; nums[pos] = i; permutation(n, pos + 1); used[i] = false; } } else { permutation(n, pos + 1); } return; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 0, 57, 64, 196, 0, 7, 15, 16, 17, 18], ["+", 0, 57, 64, 196, 0, 7, 15, 16, 17, 19]]
8
525
4
using System; namespace _2101 { class Program { static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } int x = 1; bool b = true; if (n == 1) { Console.WriteLine("deficient number"); } for (int i = 2; i <= Math.Sqrt(n) && b; i++) { if (n % i == 0) { x += i; if (i != n / i) { x += n / i; } if (n < x) { b = false; } } } if (n < x) { Console.WriteLine("abundant number"); } else if (n == x) { Console.WriteLine("perfect number"); } else { Console.WriteLine("deficient number"); } } } } }
using System; namespace _2101 { class Program { static void Main(string[] args) { while (true) { int n = int.Parse(Console.ReadLine()); if (n == 0) { break; } int x = 1; bool b = true; if (n == 1) { Console.WriteLine("deficient number"); } else { for (int i = 2; i <= Math.Sqrt(n) && b; i++) { if (n % i == 0) { x += i; if (i != n / i) { x += n / i; } if (n < x) { b = false; } } } if (n < x) { Console.WriteLine("abundant number"); } else if (n == x) { Console.WriteLine("perfect number"); } else { Console.WriteLine("deficient number"); } } } } } }
[["+", 8, 196, 0, 52, 8, 196, 0, 57, 0, 95], ["+", 0, 52, 8, 196, 0, 57, 75, 196, 0, 45], ["+", 75, 196, 0, 57, 75, 57, 75, 196, 0, 46]]
8
191
3
/* Rummy (????????????????????????????????´???) */ using System; namespace rummy_card { class Program { static void Main(string[] args) { int n = ReadNumber(); for (int i = 0; i < n; i++) { Hand rummyHand = new Hand(); Console.WriteLine(rummyHand.IsWinner() ? "1" : "0"); } } /// <summary> /// ?¨?????????????????????????????????´??°??????????????¨??????????????????????????? /// AOJ????????§?????????????????? /// </summary> /// <returns>??????????????????????????°????????????????????£?????´??°???</returns> private static int ReadNumber() { int n = 0; if (!int.TryParse(Console.ReadLine(), out n)) { /*???????????±??????????????\????????? * ????????¨??????????????????0??¨??????*/ Console.WriteLine("error:ReadNumber"); } return n; } } } /// <summary> /// ?????????????????? /// </summary> public class Card { /// <summary> /// ??????????????? /// </summary> public string _color = null; /// <summary> /// ??????????????°??? /// </summary> public int _number = 0; /// <summary> /// ????????????ID /// ??°??????????????????????????????4??????????????§??????????????§1???4???????????????????????¨?????? /// </summary> public int _id = 0; /// <summary> /// ????????????????????? /// Hand???????????????????????????????????°?????? /// ????????´???_id???Hand??????????????? /// </summary> public Card(string color, string number) { _color = color; _number = int.Parse(number); } } /// <summary> /// ??????????????? /// 9????????§???????????????????????¨???????????? /// </summary> public class Hand { Card[] _cards = new Card[9]; /// <summary> /// ????????????????????? /// ?????°?????????AOJ????????¨????????? /// </summary> public Hand() { string[] number = Console.ReadLine().Split(' '); string[] color = Console.ReadLine().Split(' '); for (int i = 0; i < 9; i++) { _cards[i] = new Card(color[i], number[i]); int ID = 1; //???????????????_id for (int j = 0; j < i; j++) { if (_cards[j]._color == _cards[i]._color && _cards[j]._number == _cards[i]._number) { ID++; //?????¨??°???????????´???????????????????????????????????????????????????ID????????????????????????????????? } } _cards[i]._id = ID; } Sort(); //??????????????±????????????????????£????????????????????????????????? } /// <summary> /// ???????????¶????????¨??????????????????????????°??¨??? /// </summary> internal void Display() { for (int i = 0; i < 9; i++) { Console.Write(_cards[i]._color + _cards[i]._number + "({0}) ", _cards[i]._id); } Console.WriteLine(); } internal bool IsWinner() { /*?????£????????????true ?????£?????????????????????false*/ bool[] flag = new bool[9]; for (int i = 0; i < 9; i++) { if (!flag [i]) //??°??????????????????????????????????????§??????????????????????????????????????????????????????????????¨??????????????? { MeldGroup(flag, i); } if (!flag[i]) //???????????£????????§???????????????????????? { MeldRun(flag, i); } if (!flag[i]) { ShowFlag(flag); return false; //??????????????±??????????????????????????????????????£??????????????§????????? } } /*false???????????????for???????????????????????´?????¨??????flag???true*/ return true; } /// <summary> /// ????????°?????¶????????¨??? ???????????°??¨ /// </summary> /// <param name="flag"></param> private void ShowFlag(bool[] flag) { foreach (bool x in flag) { Console.Write(x ? "1 " : "0 "); } Console.WriteLine(); } /// <summary> /// ????????§???????????§?????????????????? /// </summary> /// <param /// name="flag">???????????????????????£???????????£???????????????</param> /// <param name="i">???????????°</param> private void MeldRun(bool[] flag, int i) { for ( int j = i + 1; j < 9; j++) //???????????£?????????????????????????????§??°??????1??§???????????????????????????????????? { if (_cards[i]._color == _cards[j]._color && _cards[i]._number + 1 == _cards[j]._number && !flag[j]) { for ( int k = j + 1; k < 9; k++) // 1??§?????????????????????????????£?????????????§????2??§???????????????????????????????????? { if (_cards[i]._color == _cards[k]._color && _cards[i]._number + 2 == _cards[k]._number && !flag[k]) { flag[i] = true; flag[j] = true; flag[k] = true; return; } } } } } /// <summary> /// ??°???????????§???????????§?????????????????? /// </summary> /// <param /// name="flag">???????????????????????£???????????£???????????????</param> /// <param name="i">???????????°</param> private void MeldGroup(bool[] flag, int i) { if (_cards[i]._id >= 3) { flag[i] = true; flag[i + 1] = true; flag[i + 2] = true; } } /// <summary> /// ???????????´???????????????????????? /// </summary> internal void Sort() { Array.Sort(_cards, (a, b) => Compare(a, b)); } /// <summary> /// 2?????????????????? ??? > ??°??? > ID ?????????????????§???????????? /// </summary> /// <param name="a">??????????±?</param> /// <param name="b">??????????±?</param> /// <returns></returns> private int Compare(Card a, Card b) { int iCompare = b._color.CompareTo(a._color); //??????????????§???????????? if (iCompare != 0) { return iCompare; } else //?????????????????°??????????????§???????????? { if (a._number - b._number != 0) { return a._number - b._number; } else //??°??????????????????id???????????§???????????? { return b._id - a._id; } } } }
/* Rummy (????????????????????????????????´???) */ using System; namespace rummy_card { class Program { static void Main(string[] args) { int n = ReadNumber(); for (int i = 0; i < n; i++) { Hand rummyHand = new Hand(); Console.WriteLine(rummyHand.IsWinner() ? "1" : "0"); } } /// <summary> /// ?¨?????????????????????????????????´??°??????????????¨??????????????????????????? /// AOJ????????§?????????????????? /// </summary> /// <returns>??????????????????????????°????????????????????£?????´??°???</returns> private static int ReadNumber() { int n = 0; if (!int.TryParse(Console.ReadLine(), out n)) { /*???????????±??????????????\????????? * ????????¨??????????????????0??¨??????*/ Console.WriteLine("error:ReadNumber"); } return n; } } } /// <summary> /// ?????????????????? /// </summary> public class Card { /// <summary> /// ??????????????? /// </summary> public string _color = null; /// <summary> /// ??????????????°??? /// </summary> public int _number = 0; /// <summary> /// ????????????ID /// ??°??????????????????????????????4??????????????§??????????????§1???4???????????????????????¨?????? /// </summary> public int _id = 0; /// <summary> /// ????????????????????? /// Hand???????????????????????????????????°?????? /// ????????´???_id???Hand??????????????? /// </summary> public Card(string color, string number) { _color = color; _number = int.Parse(number); } } /// <summary> /// ??????????????? /// 9????????§???????????????????????¨???????????? /// </summary> public class Hand { Card[] _cards = new Card[9]; /// <summary> /// ????????????????????? /// ?????°?????????AOJ????????¨????????? /// </summary> public Hand() { string[] number = Console.ReadLine().Split(' '); string[] color = Console.ReadLine().Split(' '); for (int i = 0; i < 9; i++) { _cards[i] = new Card(color[i], number[i]); int ID = 1; //???????????????_id for (int j = 0; j < i; j++) { if (_cards[j]._color == _cards[i]._color && _cards[j]._number == _cards[i]._number) { ID++; //?????¨??°???????????´???????????????????????????????????????????????????ID????????????????????????????????? } } _cards[i]._id = ID; } Sort(); //??????????????±????????????????????£????????????????????????????????? } /// <summary> /// ???????????¶????????¨??????????????????????????°??¨??? /// </summary> internal void Display() { for (int i = 0; i < 9; i++) { Console.Write(_cards[i]._color + _cards[i]._number + "({0}) ", _cards[i]._id); } Console.WriteLine(); } internal bool IsWinner() { /*?????£????????????true ?????£?????????????????????false*/ bool[] flag = new bool[9]; for (int i = 0; i < 9; i++) { if (!flag [i]) //??°??????????????????????????????????????§??????????????????????????????????????????????????????????????¨??????????????? { MeldGroup(flag, i); } if (!flag[i]) //???????????£????????§???????????????????????? { MeldRun(flag, i); } if (!flag[i]) { return false; //??????????????±??????????????????????????????????????£??????????????§????????? } } /*false???????????????for???????????????????????´?????¨??????flag???true*/ return true; } /// <summary> /// ????????°?????¶????????¨??? ???????????°??¨ /// </summary> /// <param name="flag"></param> private void ShowFlag(bool[] flag) { foreach (bool x in flag) { Console.Write(x ? "1 " : "0 "); } Console.WriteLine(); } /// <summary> /// ????????§???????????§?????????????????? /// </summary> /// <param /// name="flag">???????????????????????£???????????£???????????????</param> /// <param name="i">???????????°</param> private void MeldRun(bool[] flag, int i) { for ( int j = i + 1; j < 9; j++) //???????????£?????????????????????????????§??°??????1??§???????????????????????????????????? { if (_cards[i]._color == _cards[j]._color && _cards[i]._number + 1 == _cards[j]._number && !flag[j]) { for ( int k = j + 1; k < 9; k++) // 1??§?????????????????????????????£?????????????§????2??§???????????????????????????????????? { if (_cards[i]._color == _cards[k]._color && _cards[i]._number + 2 == _cards[k]._number && !flag[k]) { flag[i] = true; flag[j] = true; flag[k] = true; return; } } } } } /// <summary> /// ??°???????????§???????????§?????????????????? /// </summary> /// <param /// name="flag">???????????????????????£???????????£???????????????</param> /// <param name="i">???????????°</param> private void MeldGroup(bool[] flag, int i) { if (_cards[i]._id >= 3) { flag[i] = true; flag[i + 1] = true; flag[i + 2] = true; } } /// <summary> /// ???????????´???????????????????????? /// </summary> internal void Sort() { Array.Sort(_cards, (a, b) => Compare(a, b)); } /// <summary> /// 2?????????????????? ??? > ??°??? > ID ?????????????????§???????????? /// </summary> /// <param name="a">??????????±?</param> /// <param name="b">??????????±?</param> /// <returns></returns> private int Compare(Card a, Card b) { int iCompare = b._color.CompareTo(a._color); //??????????????§???????????? if (iCompare != 0) { return iCompare; } else //?????????????????°??????????????§???????????? { if (a._number - b._number != 0) { return a._number - b._number; } else //??°??????????????????id???????????§???????????? { return b._id - a._id; } } } }
[["-", 0, 57, 64, 196, 0, 1, 0, 213, 63, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 24], ["-", 0, 1, 0, 213, 3, 4, 0, 28, 0, 22], ["-", 64, 196, 0, 1, 0, 213, 3, 4, 0, 25], ["-", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35]]
8
895
5
#define TEST #undef TEST //実装時にはこれをコメントアウトしないようにすること using System; using System.Collections.Generic; using System.Linq; using System.Text; using sc = Scanner; class Program { static void Main(string[] args) { var q = new AnswerCollecter<int>(); while (true) { int n = sc.NextInt(); if (n == 0) break; int count = 0; for (int i = 2;; i++) { int tmp = 0; for (int j = 1; j < i + 1; j++) { tmp += j + 1; } if (tmp > n) break; for (int j = 0;; j++) { if (tmp == n) { count++; break; } else if (tmp > n) break; tmp = tmp + i; //分割数 = 分割数に追加する項 - 分割数の初項 } } q.Enqueue(count); } q.Answer(); #if TEST Console.ReadLine(); #endif } } public class AnswerCollecter<T> { private Queue<T> q; public AnswerCollecter() { q = new Queue<T>(); } public void Enqueue(T item) { q.Enqueue(item); } public void Answer() { while (q.Count != 0) Console.WriteLine(q.Dequeue()); } public int Count() { return q.Count; } } public static class Scanner { public static string NextString() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return tmp; } public static string[] NextStrArray() { return Console.ReadLine().Split(' '); } public static long[] NextLongArray() { string[] s = NextStrArray(); long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = long.Parse(s[i]); } return a; } public static int[] NextIntArray() { string[] s = NextStrArray(); int[] a = new int[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = int.Parse(s[i]); } return a; } public static int NextInt() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return int.Parse(tmp); } public static double NextDouble() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return double.Parse(tmp); } public static long NextLong() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return long.Parse(tmp); } public static double[] NextDoubleArray() { string[] s = NextStrArray(); double[] a = new double[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = double.Parse(s[i]); } return a; } }
#define TEST #undef TEST //実装時にはこれをコメントアウトしないようにすること using System; using System.Collections.Generic; using System.Linq; using System.Text; using sc = Scanner; class Program { static void Main(string[] args) { var q = new AnswerCollecter<int>(); while (true) { int n = sc.NextInt(); if (n == 0) break; int count = 0; for (int i = 2;; i++) { int tmp = 0; for (int j = 0; j < i; j++) { tmp += j + 1; } if (tmp > n) break; for (int j = 0;; j++) { if (tmp == n) { count++; break; } else if (tmp > n) break; tmp = tmp + i; //分割数 = 分割数に追加する項 - 分割数の初項 } } q.Enqueue(count); } q.Answer(); #if TEST Console.ReadLine(); #endif } } public class AnswerCollecter<T> { private Queue<T> q; public AnswerCollecter() { q = new Queue<T>(); } public void Enqueue(T item) { q.Enqueue(item); } public void Answer() { while (q.Count != 0) Console.WriteLine(q.Dequeue()); } public int Count() { return q.Count; } } public static class Scanner { public static string NextString() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return tmp; } public static string[] NextStrArray() { return Console.ReadLine().Split(' '); } public static long[] NextLongArray() { string[] s = NextStrArray(); long[] a = new long[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = long.Parse(s[i]); } return a; } public static int[] NextIntArray() { string[] s = NextStrArray(); int[] a = new int[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = int.Parse(s[i]); } return a; } public static int NextInt() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return int.Parse(tmp); } public static double NextDouble() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return double.Parse(tmp); } public static long NextLong() { string tmp = ""; while (true) { string readData = char.ConvertFromUtf32(Console.Read()); if (readData == " " || readData == "\n") break; tmp += readData; } return long.Parse(tmp); } public static double[] NextDoubleArray() { string[] s = NextStrArray(); double[] a = new double[s.Length]; for (int i = 0; i < a.Length; i++) { a[i] = double.Parse(s[i]); } return a; } }
[["-", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["+", 0, 7, 10, 198, 0, 200, 0, 212, 0, 203], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 17, 72], ["-", 8, 196, 0, 7, 15, 16, 12, 16, 12, 203]]
8
764
4
using System; namespace TestProject { class MainClass { public static void Main(string[] args) { string s = Console.ReadLine(); int len = s.Length; int count = 0; for (int i = 0; i <= len / 2; i++) { switch (s[i]) { case '(': if (s[len - 1 - i] != ')') count++; break; case ')': if (s[len - 1 - i] != '(') count++; break; default: if (s[len - 1 - i] != s[i]) count++; break; } } if (len % 2 == 1) { char c = s[len / 2]; string test = "iw "; if (!test.Contains(c.ToString())) { count++; } } Console.WriteLine(count); } } }
using System; namespace TestProject { class MainClass { public static void Main(string[] args) { string s = Console.ReadLine(); int len = s.Length; int count = 0; for (int i = 0; i < len / 2; i++) { switch (s[i]) { case '(': if (s[len - 1 - i] != ')') count++; break; case ')': if (s[len - 1 - i] != '(') count++; break; default: if (s[len - 1 - i] != s[i]) count++; break; } } if (len % 2 == 1) { char c = s[len / 2]; string test = "iw "; if (!test.Contains(c.ToString())) { count++; } } Console.WriteLine(count); } } }
[["-", 0, 195, 8, 196, 0, 7, 15, 16, 17, 19], ["+", 0, 195, 8, 196, 0, 7, 15, 16, 17, 18]]
8
197
2
using System; public class Hello { public static void Main() { var f = new int[100003]; var fsum = new int[100003]; var n = int.Parse(Console.ReadLine().Trim()); var bmax = 0; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); bmax = Math.Max(bmax, b); f[a]++; f[b + 1]--; } fsum[1] = f[1]; for (int i = 2; i <= bmax; i++) fsum[i] = fsum[i - 1] + f[i]; var imax = 0; for (int i = 2; i <= n + 1; i++) if (fsum[i] >= i) imax = i; Console.WriteLine(imax == 0 ? 0 : imax - 1); } }
using System; public class Hello { public static void Main() { var f = new int[100003]; var fsum = new int[100003]; var n = int.Parse(Console.ReadLine().Trim()); var bmax = 0; for (int i = 0; i < n; i++) { string[] line = Console.ReadLine().Trim().Split(' '); var a = int.Parse(line[0]); var b = int.Parse(line[1]); bmax = Math.Max(bmax, b); f[a]++; f[b + 1]--; } fsum[1] = f[1]; for (int i = 2; i <= bmax; i++) fsum[i] = fsum[i - 1] + f[i]; var imax = 0; for (int i = 2; i <= n + 1; i++) if (fsum[i] + 1 >= i) imax = i; Console.WriteLine(imax == 0 ? 0 : imax - 1); } }
[["+", 0, 7, 8, 57, 15, 16, 31, 16, 17, 72], ["+", 0, 7, 8, 57, 15, 16, 31, 16, 12, 203]]
8
236
2
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; // static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n, m, k; sc.Multi(out n, out m, out k); long ans = 0; var cb = mymath.getcomb(n + m + k * 2); mymath.setfacts(Math.Max(n, m) + k * 2 + 1); for (int i = 0; i <= k; i++) ans = (ans + (mymath.comb(n + i * 2, i) - mymath.comb(n + i * 2, i - 1)) * (mymath.comb(m + (k - i) * 2, k - i) - mymath.comb(m + (k - i) * 2, k - i - 1)) % M * cb[n + i * 2] % M + M) % M; Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } // static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } // static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } // static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } // static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ static string Join<T>(string sep, IEnumerable<T> a) { return string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long[] facts, invs; public static void setfacts(int n) { facts = new long[n + 1]; invs = new long[n + 1]; facts[0] = invs[0] = 1; for (int i = 0; i < n; i++) { facts[i + 1] = facts[i] * (i + 1) % Mod; invs[i + 1] = inv(facts[i + 1]); } } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts.Length > n) return facts[n] * invs[r] * invs[n - r]; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; using System.Text; using System.Diagnostics; using Binary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.BinaryExpression>; using Unary = System.Func<System.Linq.Expressions.ParameterExpression, System.Linq.Expressions.UnaryExpression>; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; static Scan sc = new Scan(); const int M = 1000000007; const double eps = 1e-11; // static readonly int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n, m, k; sc.Multi(out n, out m, out k); long ans = 0; var cb = mymath.getcomb(n + m + k * 2); mymath.setfacts(Math.Max(n, m) + k * 2 + 1); for (int i = 0; i <= k; i++) ans = (ans + (mymath.comb(n + i * 2, i) - mymath.comb(n + i * 2, i - 1)) * (mymath.comb(m + (k - i) * 2, k - i) - mymath.comb(m + (k - i) * 2, k - i - 1)) % M * cb[n + i * 2] % M + M) % M; Prt(ans); sw.Flush(); } static void swap<T>(ref T a, ref T b) { var t = a; a = b; b = t; } static T Max<T>(params T[] a) { return a.Max(); } static T Min<T>(params T[] a) { return a.Min(); } static void DBG(string a) { Console.WriteLine(a); } // static void DBG<T>(IEnumerable<T> a) { DBG(string.Join(" ", a)); } // static void DBG(params object[] a) { DBG(string.Join(" ", a)); } static void Prt(string a) { sw.WriteLine(a); } // static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); } // static void Prt(params object[] a) { Prt(string.Join(" ", a)); } // for AOJ static string Join<T>(string sep, IEnumerable<T> a) { return string.Join(sep, a.Select(x => x.ToString()).ToArray()); } static void DBG<T>(IEnumerable<T> a) { DBG(Join(" ", a)); } static void DBG(params object[] a) { DBG(Join(" ", a)); } static void Prt<T>(IEnumerable<T> a) { Prt(Join(" ", a)); } static void Prt(params object[] a) { Prt(Join(" ", a)); } } static class ex { public static void swap<T>(this IList<T> a, int i, int j) { var t = a[i]; a[i] = a[j]; a[j] = t; } public static T[] copy<T>(this IList<T> a) { var ret = new T[a.Count]; for (int i = 0; i < a.Count; i++) ret[i] = a[i]; return ret; } } static class Operator<T> { static readonly ParameterExpression x = Expression.Parameter(typeof(T), "x"); static readonly ParameterExpression y = Expression.Parameter(typeof(T), "y"); public static readonly Func<T, T, T> Add = Lambda(Expression.Add); public static readonly Func<T, T, T> Subtract = Lambda(Expression.Subtract); public static readonly Func<T, T, T> Multiply = Lambda(Expression.Multiply); public static readonly Func<T, T, T> Divide = Lambda(Expression.Divide); public static readonly Func<T, T> Plus = Lambda(Expression.UnaryPlus); public static readonly Func<T, T> Negate = Lambda(Expression.Negate); public static Func<T, T, T> Lambda(Binary op) { return Expression.Lambda<Func<T, T, T>>(op(x, y), x, y).Compile(); } public static Func<T, T> Lambda(Unary op) { return Expression.Lambda<Func<T, T>>(op(x), x).Compile(); } } class Scan { public int Int { get { return int.Parse(Str); } } public long Long { get { return long.Parse(Str); } } public double Double { get { return double.Parse(Str); } } public string Str { get { return Console.ReadLine().Trim(); } } public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } } public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } } public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } } public string[] StrArr { get { return Str.Split(); } } bool eq<T, U>() { return typeof(T).Equals(typeof(U)); } T ct<T, U>(U a) { return (T)Convert.ChangeType(a, typeof(T)); } T cv<T>(string s) { return eq<T, int>() ? ct<T, int>(int.Parse(s)) : eq<T, long>() ? ct<T, long>(long.Parse(s)) : eq<T, double>() ? ct<T, double>(double.Parse(s)) : eq<T, char>() ? ct<T, char>(s[0]) : ct<T, string>(s); } public void Multi<T>(out T a) { a = cv<T>(Str); } public void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } public void Multi<T, U, V, W, X, Y>(out T a, out U b, out V c, out W d, out X e, out Y f) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); } public void Multi<T, U, V, W, X, Y, Z>(out T a, out U b, out V c, out W d, out X e, out Y f, out Z g) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); f = cv<Y>(ar[5]); g = cv<Z>(ar[6]); } } static class mymath { public static long Mod = 1000000007; public static bool isprime(long a) { if (a < 2) return false; for (long i = 2; i * i <= a; i++) if (a % i == 0) return false; return true; } public static bool[] sieve(int n) { var p = new bool[n + 1]; for (int i = 2; i <= n; i++) p[i] = true; for (int i = 2; i * i <= n; i++) if (p[i]) for (int j = i * i; j <= n; j += i) p[j] = false; return p; } public static List<int> getprimes(int n) { var prs = new List<int>(); var p = sieve(n); for (int i = 2; i <= n; i++) if (p[i]) prs.Add(i); return prs; } public static long[][] E(int n) { var ret = new long [n][]; for (int i = 0; i < n; i++) { ret[i] = new long[n]; ret[i][i] = 1; } return ret; } public static double[][] dE(int n) { var ret = new double [n][]; for (int i = 0; i < n; i++) { ret[i] = new double[n]; ret[i][i] = 1; } return ret; } public static long[][] pow(long[][] A, long n) { if (n == 0) return E(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double[][] pow(double[][] A, long n) { if (n == 0) return dE(A.Length); var t = pow(A, n / 2); if ((n & 1) == 0) return mul(t, t); return mul(mul(t, t), A); } public static double dot(double[] x, double[] y) { int n = x.Length; double ret = 0; for (int i = 0; i < n; i++) ret += x[i] * y[i]; return ret; } public static double _dot(double[] x, double[] y) { int n = x.Length; double ret = 0, r = 0; for (int i = 0; i < n; i++) { double s = ret + (x[i] * y[i] + r); r = (x[i] * y[i] + r) - (s - ret); ret = s; } return ret; } public static long dot(long[] x, long[] y) { int n = x.Length; long ret = 0; for (int i = 0; i < n; i++) ret = (ret + x[i] * y[i]) % Mod; return ret; } public static T[][] trans<T>(T[][] A) { int n = A[0].Length, m = A.Length; var ret = new T[n][]; for (int i = 0; i < n; i++) { ret[i] = new T[m]; for (int j = 0; j < m; j++) ret[i][j] = A[j][i]; } return ret; } public static double[] mul(double[][] A, double[] x) { int n = A.Length; var ret = new double[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[] mul(long[][] A, long[] x) { int n = A.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = dot(x, A[i]); return ret; } public static long[][] mul(long[][] A, long[][] B) { int n = A.Length; var Bt = trans(B); var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static double[][] mul(double[][] A, double[][] B) { int n = A.Length; var Bt = trans(B); var ret = new double [n][]; for (int i = 0; i < n; i++) ret[i] = mul(Bt, A[i]); return ret; } public static long[] add(long[] x, long[] y) { int n = x.Length; var ret = new long[n]; for (int i = 0; i < n; i++) ret[i] = (x[i] + y[i]) % Mod; return ret; } public static long[][] add(long[][] A, long[][] B) { int n = A.Length; var ret = new long [n][]; for (int i = 0; i < n; i++) ret[i] = add(A[i], B[i]); return ret; } public static long pow(long a, long b) { if (a >= Mod) return pow(a % Mod, b); if (a == 0) return 0; if (b == 0) return 1; var t = pow(a, b / 2); if ((b & 1) == 0) return t * t % Mod; return t * t % Mod * a % Mod; } public static long inv(long a) { return pow(a, Mod - 2); } public static long gcd(long a, long b) { while (b > 0) { var t = a % b; a = b; b = t; } return a; } // a x + b y = gcd(a, b) public static long extgcd(long a, long b, out long x, out long y) { long g = a; x = 1; y = 0; if (b > 0) { g = extgcd(b, a % b, out y, out x); y -= a / b * x; } return g; } public static long lcm(long a, long b) { return a / gcd(a, b) * b; } static long[] facts, invs; public static void setfacts(int n) { facts = new long[n + 1]; invs = new long[n + 1]; facts[0] = invs[0] = 1; for (int i = 0; i < n; i++) { facts[i + 1] = facts[i] * (i + 1) % Mod; invs[i + 1] = inv(facts[i + 1]); } } public static long comb(int n, int r) { if (n < 0 || r < 0 || r > n) return 0; if (n - r < r) r = n - r; if (r == 0) return 1; if (r == 1) return n; if (facts.Length > n) return facts[n] * invs[r] % Mod * invs[n - r] % Mod; int[] numer = new int[r], denom = new int[r]; for (int k = 0; k < r; k++) { numer[k] = n - r + k + 1; denom[k] = k + 1; } for (int p = 2; p <= r; p++) { int piv = denom[p - 1]; if (piv > 1) { int ofst = (n - r) % p; for (int k = p - 1; k < r; k += p) { numer[k - ofst] /= piv; denom[k] /= piv; } } } long ret = 1; for (int k = 0; k < r; k++) if (numer[k] > 1) ret = ret * numer[k] % Mod; return ret; } public static long[][] getcombs(int n) { var ret = new long [n + 1][]; for (int i = 0; i <= n; i++) { ret[i] = new long[i + 1]; ret[i][0] = ret[i][i] = 1; for (int j = 1; j < i; j++) ret[i][j] = (ret[i - 1][j - 1] + ret[i - 1][j]) % Mod; } return ret; } // nC0, nC2, ..., nCn public static long[] getcomb(int n) { var ret = new long[n + 1]; ret[0] = 1; for (int i = 0; i < n; i++) ret[i + 1] = ret[i] * (n - i) % Mod * inv(i + 1) % Mod; return ret; } }
[["+", 64, 37, 0, 16, 31, 16, 31, 16, 17, 109], ["+", 64, 37, 0, 16, 31, 16, 31, 16, 12, 22], ["+", 8, 196, 0, 57, 64, 37, 0, 16, 17, 109], ["+", 8, 196, 0, 57, 64, 37, 0, 16, 12, 22]]
8
3,981
4
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY { public int X, Y; public int SQLength() { return X * X + Y * Y; } public bool Flag = false; public PointXY(int _X, int _Y) { X = _X; Y = _Y; } public PointXY(PointXY P1, int _X = 0, int _Y = 0) { X = P1.X + _X; Y = P1.Y + _Y; } public static bool operator ==(PointXY P1, PointXY P2) { return (P1.X == P2.X && P1.Y == P2.Y); } public static bool operator !=(PointXY P1, PointXY P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY)obj); } } public class Lib72 { public static int NumFromChar(char CNUM) { return CNUM - 48; } public static char LoopChar52(char _C, int n) { // Char(C#) uses Uni-Code // 33 ! "#$%&'( 41 ) // 42 * +,-. 47/ // 48 0 .... 57 9 // 58 :;<=>? 64 @ // 65 A .... 90 Z // 91 [\]^_ 96` // 97 a .... 122 z int i_C = (int)_C; if (i_C > 64 && i_C < 91) i_C -= 65; // 0~25 AZ else if (i_C > 96 && i_C < 123) i_C -= 61; // 26~51 az else return '0'; int RESULT = Modulo((i_C + n), 52); if (RESULT < 26) return (char)(RESULT + 65); else return (char)(RESULT + 61); } public static int Modulo(int A, int B) { // -6 % 5 == -1 // -6 % 5 == 4 int Result = A % B; if (Result >= 0) { return Result; } else return Result + B; } public static int[] KETAArray(int Num) { return KETAArray(Num.ToString()); } public static int[] KETAArray(string Num) { char[] cKETA = Num.ToCharArray(); int[] iKETA = new int[cKETA.Length]; for (int i = 0; i < iKETA.Length; i++) { iKETA[i] = NumFromChar(cKETA[i]); } return iKETA; } public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; } public static int FromKETAArray(int[] _ketaarray) { int result = 0; int[] R_ketaarray = _ketaarray.Reverse().ToArray(); for (int i = 0, j = 1; i < R_ketaarray.Length; i++, j *= 10) { result += j * R_ketaarray[i]; } return result; } public static bool isPrime(int p) { if (p != 2 && p % 2 == 0) return false; if (p == 1) return false; int SQp = (int)(Math.Sqrt(p)); for (int i = 3; i <= SQp; i++) { if (p % i == 0) return false; } return true; } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true, int FinNum = 0) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == FinNum && num2 == FinNum); } static int[] ReadLine_Array(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const int DefaultMax = 72727272; static void Main(string[] args) { while (true) { int n = ReadLine_1(); if (n == 0) return; int[] Keys = ReadLine_Array(); char[] Lists = Console.ReadLine().ToCharArray(); for (int i = 0; i < Lists.Length; i++) { Lists[i] = Lib72.LoopChar52(Lists[i], -Keys[i % Keys.Length]); } Console.WriteLine(Lists); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using CHY72; namespace CHY72 { public class PointXY { public int X, Y; public int SQLength() { return X * X + Y * Y; } public bool Flag = false; public PointXY(int _X, int _Y) { X = _X; Y = _Y; } public PointXY(PointXY P1, int _X = 0, int _Y = 0) { X = P1.X + _X; Y = P1.Y + _Y; } public static bool operator ==(PointXY P1, PointXY P2) { return (P1.X == P2.X && P1.Y == P2.Y); } public static bool operator !=(PointXY P1, PointXY P2) { return !(P1 == P2); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return false; } return (this == (PointXY)obj); } } public class Lib72 { public static int NumFromChar(char CNUM) { return CNUM - 48; } public static char LoopChar52(char _C, int n) { // Char(C#) uses Uni-Code // 33 ! "#$%&'( 41 ) // 42 * +,-. 47/ // 48 0 .... 57 9 // 58 :;<=>? 64 @ // 65 A .... 90 Z // 91 [\]^_ 96` // 97 a .... 122 z int i_C = (int)_C; if (i_C > 64 && i_C < 91) i_C -= 65; // 0~25 AZ else if (i_C > 96 && i_C < 123) i_C -= 71; // 26~51 az else return '0'; int RESULT = Modulo((i_C + n), 52); if (RESULT < 26) return (char)(RESULT + 65); else return (char)(RESULT + 71); } public static int Modulo(int A, int B) { // -6 % 5 == -1 // -6 % 5 == 4 int Result = A % B; if (Result >= 0) { return Result; } else return Result + B; } public static int[] KETAArray(int Num) { return KETAArray(Num.ToString()); } public static int[] KETAArray(string Num) { char[] cKETA = Num.ToCharArray(); int[] iKETA = new int[cKETA.Length]; for (int i = 0; i < iKETA.Length; i++) { iKETA[i] = NumFromChar(cKETA[i]); } return iKETA; } public static int KETA(int Num) { return Num.ToString().ToCharArray().Length; } public static int FromKETAArray(int[] _ketaarray) { int result = 0; int[] R_ketaarray = _ketaarray.Reverse().ToArray(); for (int i = 0, j = 1; i < R_ketaarray.Length; i++, j *= 10) { result += j * R_ketaarray[i]; } return result; } public static bool isPrime(int p) { if (p != 2 && p % 2 == 0) return false; if (p == 1) return false; int SQp = (int)(Math.Sqrt(p)); for (int i = 3; i <= SQp; i++) { if (p % i == 0) return false; } return true; } } } public class Program { static bool ReadLine_1(ref int num1, bool Fin0 = true) { string str = Console.ReadLine(); num1 = int.Parse(str); return (Fin0 && num1 == 0); } static int ReadLine_1() { return int.Parse(Console.ReadLine()); } static bool ReadLine_2(ref int num1, ref int num2, char Spliter = ' ', bool Fin0 = true, int FinNum = 0) { string str = Console.ReadLine(); num1 = int.Parse(str.Split(Spliter)[0]); num2 = int.Parse(str.Split(Spliter)[1]); return (Fin0 && num1 == FinNum && num2 == FinNum); } static int[] ReadLine_Array(char Spliter = ' ') { return Console.ReadLine() .Split(Spliter) .Select(s => int.Parse(s)) .ToArray(); } const int DefaultMax = 72727272; static void Main(string[] args) { while (true) { int n = ReadLine_1(); if (n == 0) return; int[] Keys = ReadLine_Array(); char[] Lists = Console.ReadLine().ToCharArray(); for (int i = 0; i < Lists.Length; i++) { Lists[i] = Lib72.LoopChar52(Lists[i], -Keys[i % Keys.Length]); } Console.WriteLine(Lists); } } }
[["-", 0, 57, 75, 57, 64, 1, 0, 11, 12, 203], ["+", 0, 57, 75, 57, 64, 1, 0, 11, 12, 203], ["-", 75, 37, 0, 74, 51, 23, 0, 16, 12, 203], ["+", 75, 37, 0, 74, 51, 23, 0, 16, 12, 203]]
8
975
4
using System; public class AOJ2522 { static void Main() { string pass = Console.ReadLine(); bool hd = false, hu = false, hl = false; foreach (char ss in pass) { if (char.IsDigit(ss)) hd = true; else if (char.IsLower(ss)) hl = true; else if (char.IsUpper(ss)) hu = true; } if (hd && hl && hu && pass.Length >= 6) Console.WriteLine("VARID"); else Console.WriteLine("INVARID"); } }
using System; public class AOJ2522 { static void Main() { string pass = Console.ReadLine(); bool hd = false, hu = false, hl = false; foreach (char ss in pass) { if (char.IsDigit(ss)) hd = true; else if (char.IsLower(ss)) hl = true; else if (char.IsUpper(ss)) hu = true; } if (hd && hl && hu && pass.Length >= 6) Console.WriteLine("VALID"); else Console.WriteLine("INVALID"); } }
[["-", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222], ["+", 0, 213, 3, 4, 0, 28, 0, 5, 0, 222]]
8
120
4