Skip to content
Loading
  • Laxmidhar Sahoo
    +1
    sir according your problem explain mr
    Dharmraj Thakur is currect
    +1
  • Rajeesh Menoth
    +1
    Hi,
     
    The answer given by Altaf Ansari is wrong based on your question. The given answer only display "X" as the output. You can visit his answer through the following link.
     
    https://dotnetfiddle.net/Z8qbPv 
    +1
  • +1
    protected void Page_Load(object sender, EventArgs e)
    {
    var Answer = "A,B,D,A,D,B,A,C,B,A,C,D,B,D,B,D,D,B,A,D,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B";
    var Quiz = "x,A,B,A,D,B,A,C,B,B,C,D,B,D,B,D,D,B,A,B,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B";
    int correstresult = 0;
    int wrongresult = 0;
    string correstquestionlist = "";
    string wrongquestionlist = "";
    ArrayList correctans = new ArrayList();
    ArrayList response = new ArrayList();
    string[] Answers = Answer.Split(',');
    string[] Questions = Quiz.Split(',');
    //data add in correct arraylist
    for (int i = 0; i < Questions.Count(); i++)
    {
    response.Add(Questions[i].ToString());
    }
    for (int i = 0; i < Answers.Count(); i++)
    {
    correctans.Add(Answers[i].ToString());
    }
    for (int j = 0; j < Questions.Count(); j++)
    {
    if (correctans[j] == response[j])
    {
    correstresult++;
    if (correstquestionlist == "")
    {
    correstquestionlist = (j + 1).ToString();
    }
    else
    {
    correstquestionlist = correstquestionlist + "," + (j + 1).ToString();
    }
    }
    else
    {
    wrongresult++;
    if (wrongquestionlist == "")
    {
    wrongquestionlist = (j + 1).ToString();
    }
    else
    {
    wrongquestionlist = wrongquestionlist + "," + (j + 1).ToString();
    }
    }
    Label1.Text = wrongquestionlist;
    Label2.Text = correstquestionlist;
    }
    }
    +1
  • +1
    SOLUTION
    1. var Answer = "A,B,D,A,D,B,A,C,B,A,C,D,B,D,B,D,D,B,A,D,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B".Split(',').ToArray();  
    2. var Quiz = "x,A,B,A,D,B,A,C,B,B,C,D,B,D,B,D,D,B,A,B,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B".Split(',').ToArray();  
    3. var process = Answer.Select( (a,index)=> new{ a, index})  
    4. .Where(a => a.a != Quiz[a.index])  
    5. .Select (a =>new{index= (a.index+1),Quiz= Quiz[a.index]})  
    6. foreach(var p in process)  
    7. {  
    8. Console.Write(String.Format("{0}{1},",p.a,p.index));  
    9. }  
    Output
     
    A1,B2,D3,A10,D20,
    +1
  • Altaf Ansari
    -1
    Please try this ;
     
    1. string Answer = "A,B,D,A,D,B,A,C,B,A,C,D,B,D,B,D,D,B,A,D,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B";  
    2.            string Quiz = "x,A,B,A,D,B,A,C,B,B,C,D,B,D,B,D,D,B,A,B,D,B,B,A,B,A,D,C,B,C,C,B,A,A,C,A,D,B,C,C,A,D,A,D,A,B,B,B,A,B";  
    3.            string result = string.Join(",",Quiz.Split(',').Where(item => !Answer.Split(',').ToList().Contains(item)).ToArray()); 
     
    -1