あにす #6862(2008/07/27 08:51 GMT) [ C# ] Rating0/0=0.00
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
using System; using System.Collections.Generic; using System.IO; class Program { static void Main(string[] args) { RandomWalk rndwalk = new RandomWalk(int.Parse(args[0])); while(true) { if(Console.ReadLine() != "end") { foreach(int i in rndwalk.Tic()) { Console.Write(i.ToString() + " "); } Console.WriteLine(); } else { break; } } rndwalk.WriteLog(Environment.CurrentDirectory + "\\" + args[1]); using(StreamReader sr = new StreamReader(Environment.CurrentDirectory + "\\" + args[1])) { while(!sr.EndOfStream) { Console.WriteLine(sr.ReadLine()); } } Console.ReadLine(); } } class RandomWalk { int rank; List<int[]> log = new List<int[]>(); Random rnd = new Random(); int[] direction = new int[] { -1, 1 }; public RandomWalk(int rank) { this.rank = rank; log.Add(new int[rank]); } public int[] Tic() { int changeRank = rnd.Next(0, rank); int[] pre = log[log.Count - 1]; int[] ticedPoint = new int[rank]; for(int i = 0; i < rank; i++) { if(i == changeRank) { ticedPoint[i] = pre[i] + direction[rnd.Next(0, 2)]; } else { ticedPoint[i] = pre[i]; } } log.Add(ticedPoint); return log[log.Count - 1]; } public void WriteLog(string fileName) { using(StreamWriter sw = new StreamWriter(fileName)) { for(int time = 0; time < log.Count; time++) { int[] point = log[time]; sw.Write(time + " "); foreach(int i in point) { sw.Write(i.ToString() + " "); } sw.WriteLine(); } sw.Close(); } } }
Rating0/0=0.00-0+
[ reply ]
あにす
#6862()
[
C#
]
Rating0/0=0.00
Rating0/0=0.00-0+
[ reply ]