.net - c# Getting runtime error. Why? -
hey im trying solve problem kattis says runtime error means uncaught exception. https://open.kattis.com/problems/fizzbuzz
is there ive missed in code crashes app?
public static void main(string[] args) { string line = ""; while ((line = console.readline()) != "0") { var numbers = line.split(' ').select(int.parse).tolist(); int x = numbers[0]; int y = numbers[1]; int n = numbers[2]; for(int = 1; <= n; i++) { bool found = false; bool found2 = false; if(i % x == 0) { if(i % y==0) { console.writeline("fizzbuzz"); found2 = true; } else { console.writeline("fizz"); found = true; } } if(i % y == 0 && !found2) { console.writeline("buzz"); found = true; } if(!found && !found2) { console.writeline(i); } } } }
the way read problem you'll given 1 line of 3 numbers on console. should doing 1 readline
. suggest removing while
loop , do.
var numbers = console.readline().split(' ').select(int.parse).tolist();
Comments
Post a Comment