如何修改C#代码中的number变量以显示二进制数而非System.ToString输出?Advent of Code任务代码求助
求助:Advent of Code 题目卡壳,还有输出问题想请教
嘿,我正在啃Advent of Code的题目,这道题已经卡了我好一会儿了😅。作为编程新手,我已经拼尽全力往前推进,但写出来的代码可能有点乱糟糟的(抱歉写出了面条式代码),希望能得到大家的帮助或者指引!
我的代码如下:
static void Main() { string path = "plik.txt"; string[] diagnostics = File.ReadAllLines(path); int diagSize = diagnostics.Length; string[] number = new string[12]; // int result = Convert.ToInt32(diagnostics[i], 2); for (int j = 0; j < 12; j++) { int ones = 0; int zeroes = 0; for (int i = 0; i < diagSize; i++) { string temp = diagnostics[i]; if (temp[j] == '1') { ones++; } else zeroes++; } if(ones > zeroes) { number[j] = "1"; } else { number[j] = "0"; } Console.WriteLine(number[j]); } Console.WriteLine(number); }
另外我还有个小问题想请教:怎么修改代码里的number变量,让它能正确显示二进制数,而不是输出System.String[]这种内容呀?
内容的提问来源于stack exchange,提问作者CasteliaZzz
相关产品推荐
相关产品推荐

