标签:style blog class code java ext
平民的代码,列表法,凑个热闹,做了简单的测试,太晚了就不写测试用例了
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace FizzBuzzWhizz 8 { 9 class Program 10 { 11 static bool checkisvalid(string val) 12 { 13 int iv = 0; 14 if (val.Split(‘,‘).Length != 3) return false; 15 if (!int.TryParse(val.Split(‘,‘)[0], out iv)) return false; 16 if (!int.TryParse(val.Split(‘,‘)[1], out iv)) return false; 17 if (!int.TryParse(val.Split(‘,‘)[2], out iv)) return false; 18 return true; 19 } 20 21 static void getvals(string val,out int a,out int b,out int c) 22 { 23 a = int.Parse(val.Split(‘,‘)[0]); 24 b = int.Parse(val.Split(‘,‘)[1]); 25 c = int.Parse(val.Split(‘,‘)[2]); 26 } 27 28 static void Main(string[] args) 29 { 30 int a, b, c; 31 32 Console.Out.WriteLine("请输入个位整数,用逗号隔开:3,5,7"); 33 string val = Console.In.ReadLine(); 34 if (!checkisvalid(val)) return; 35 getvals(val, out a, out b, out c); 36 if ((a == b) && (b == c)) return; 37 if (a == 0 || b == 0 || c == 0) return; 38 if (a > 9 || b > 9 || c > 9) return; 39 string[] bb = bizbuzwhz.process(a,b,c); 40 41 foreach(var m in bb) 42 { 43 Console.Out.WriteLine(m); 44 } 45 46 47 } 48 } 49 50 public class bizbuzwhz 51 { 52 public static string[] process(int e1,int e2,int e3) 53 { 54 string Fizz = "Fizz"; 55 string Buzz = "Buzz"; 56 string Whizz = "Whizz"; 57 string[] ele = new string[100]; 58 int pos; 59 for (int i = 0; i < 10; i++ ) 60 { 61 for (int j = 0;j<10;j++) 62 { 63 pos = (i * 10 + j); 64 ele[pos] = string.Empty; 65 if ((j + 1 == e1) && i > 0) ele[pos] += Fizz; 66 if (((pos+1) % e1) == 0) ele[pos] += Fizz; 67 if ((j + 1 == e2) && i > 0) ele[pos] += Buzz; 68 if (((pos + 1) % e2) == 0) ele[pos] += Buzz; 69 if ((j + 1 == e3) && i > 0) ele[pos] += Whizz; 70 if (((pos + 1) % e3) == 0) ele[pos] += Whizz; 71 if (ele[pos] == string.Empty) ele[pos] = (pos+1).ToString(); 72 } 73 } 74 return ele; 75 } 76 } 77 78 }
因为主要代码,所以不能放到首页,也伤心啊,代码不是一行一行的写的么,说起来系统智能程度有待加强
--------------------------------------------到此为止------------------------------------------------------------------------------
你是一名体育老师,在某次课距离下课还有五分钟时,你决定搞一个游戏。此时有100名学生在上课。游戏的规则是:
打个酱油,欢迎指正FizzBuzzWhizz(c#),布布扣,bubuko.com
标签:style blog class code java ext
原文地址:http://www.cnblogs.com/maxiaoxia/p/3715246.html