C
C#2mo ago
manuka

✅ code works fine on my pc but give runtime error on codeforces

Problem https://codeforces.com/contest/231/problem/A My Code
C#
using System;

namespace CodeForces
{
internal class Solution
{
public static void solve()
{
int n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[3];

for(int i=0;i<n;i++)
{
int x = Convert.ToInt32(Console.ReadLine());
int y = Convert.ToInt32(Console.ReadLine());
int z = Convert.ToInt32(Console.ReadLine());
a[i] = x+y+z;
}

int ans=0;
for(int i=0;i<n;i++)
{
if(a[i]>=2)
{
ans++;
}
}
Console.WriteLine(ans);
}

public static void Main(string[] args)
{
solve();
}
}
}
C#
using System;

namespace CodeForces
{
internal class Solution
{
public static void solve()
{
int n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[3];

for(int i=0;i<n;i++)
{
int x = Convert.ToInt32(Console.ReadLine());
int y = Convert.ToInt32(Console.ReadLine());
int z = Convert.ToInt32(Console.ReadLine());
a[i] = x+y+z;
}

int ans=0;
for(int i=0;i<n;i++)
{
if(a[i]>=2)
{
ans++;
}
}
Console.WriteLine(ans);
}

public static void Main(string[] args)
{
solve();
}
}
}
No description
11 Replies
ACiDCA7
ACiDCA72mo ago
did you try to replicate the input? because that input breaks your code
manuka
manukaOP2mo ago
problem doesnt tell if the input is a string or a int im still trying to figure it out
ACiDCA7
ACiDCA72mo ago
wdym? each line is a line input into the console
manuka
manukaOP2mo ago
nvm found a fix
C#
string[] numb = Console.ReadLine().Split(' ');

int x,y,z = int.Parse(numb[0]);int.Parse(numb[1]);int.Parse(numb[2]);
C#
string[] numb = Console.ReadLine().Split(' ');

int x,y,z = int.Parse(numb[0]);int.Parse(numb[1]);int.Parse(numb[2]);
do you know anyway to make it format like this
manuka
manukaOP2mo ago
No description
ACiDCA7
ACiDCA72mo ago
did chatgpt puke that out?
manuka
manukaOP2mo ago
otherwise it will look like this still works but looks ugly
C#
int x = Convert.ToInt32(numb[0]);
int y = Convert.ToInt32(numb[1]);
int z = Convert.ToInt32(numb[2]);
C#
int x = Convert.ToInt32(numb[0]);
int y = Convert.ToInt32(numb[1]);
int z = Convert.ToInt32(numb[2]);
no i found a random question on a website
ACiDCA7
ACiDCA72mo ago
code should be readable and this is more readable than cramming everything into one line like i asume you want to do also prefer tryparse instead of convert
manuka
manukaOP2mo ago
i didnt knew what was int.Parse before thats why i used convert i saw that on the website i mentioned above i will use parse from now on lol how do i mark this thread as solved @ACiDCA7
ACiDCA7
ACiDCA72mo ago
/close
Want results from more Discord servers?
Add your server