Can anyone tell me? why my solution is not accepted

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demoapplication
{
class SelectSet_CodeChef_
{
public int selectset(List<KeyValuePair<string, int>> trainingSet)
{
for (int i = 0; i < trainingSet.Count; i++)
{
for (int j = 0; j < trainingSet.Count; j++)
{
if(trainingSet.ElementAt(i).Key== trainingSet.ElementAt(j).Key)
{
if (trainingSet.ElementAt(i).Value != trainingSet.ElementAt(j).Value)
{
string temp = trainingSet.ElementAt(i).Key;
trainingSet.Remove(new KeyValuePair<string, int>(trainingSet.ElementAt(i).Key,trainingSet.ElementAt(i).Value));
}
}
}
}
int count = trainingSet.Count;
return count;
}
static void Main(string[] args)
{
var testCase = Convert.ToInt32(Console.ReadLine());
string str;
int no;
List<KeyValuePair<string,int>> trainingSet = new List<KeyValuePair<string, int>>();
for(int i =0 ;i<testCase;i++)
{
var noInput = Convert.ToInt32(Console.ReadLine());
for (int j = 0; j < noInput; j++)
{
str = Console.ReadLine();
no = Convert.ToInt32(Console.ReadLine());
trainingSet.Add(new KeyValuePair<string, int>(str,no));
}
}
SelectSet_CodeChef_ obj = new SelectSet_CodeChef_();
var count = obj.selectset(trainingSet);
Console.WriteLine(count);
}
}
}

What problem are you trying to solve? :slight_smile:

Edit:

Looks like it’s TRAINSET, and this is his code: CodeChef: Practical coding for everyone

Edit:

I’ve not used C# before (especially under Linux!) but running this in on the sample testcase gives:

echo "3                                                       
3
abc 0
abc 1
efg 1
7
fck 1
fck 0
fck 1
body 0
body 0
body 0
ram 0
5
vv 1
vv 0
vv 0
vv 1
vv 1" | mono hello.exe

Unhandled Exception:
System.FormatException: Input string was not in a correct format.
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x0005e] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00008] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Convert.ToInt32 (System.String value) [0x0000e] in <8f2c484307284b51944a1a13a14c0266>:0 
  at Demoapplication.SelectSet_CodeChef_.Main (System.String[] args) [0x00038] in <bd49cbbde12942a9b128c8ba1dbcfee5>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.FormatException: Input string was not in a correct format.
  at System.Number.StringToNumber (System.String str, System.Globalization.NumberStyles options, System.Number+NumberBuffer& number, System.Globalization.NumberFormatInfo info, System.Boolean parseDecimal) [0x0005e] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Number.ParseInt32 (System.String s, System.Globalization.NumberStyles style, System.Globalization.NumberFormatInfo info) [0x00014] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Int32.Parse (System.String s, System.IFormatProvider provider) [0x00008] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Convert.ToInt32 (System.String value) [0x0000e] in <8f2c484307284b51944a1a13a14c0266>:0 
  at Demoapplication.SelectSet_CodeChef_.Main (System.String[] args) [0x00038] in <bd49cbbde12942a9b128c8ba1dbcfee5>:0 

so it looks like you’re not reading in the testcase correctly.

In particular, this bit looks fishy:

  str = Console.ReadLine();
  no = Convert.ToInt32(Console.ReadLine());

The str and the no are provided in the same line of test input, so I don’t see how this will work.

5 Likes