CodeChef-Ciel and A-B

using System;

public class Program
  public static void Main()
    string line = Console.ReadLine();
    string[] splitLines = line.Split(' ');
    string answerText;

    int a = int.Parse(splitLines[0]);
    int b = int.Parse(splitLines[1]);
    int answerNumber = a - b;

    answerText = answerNumber.ToString();

    char[] answerChar = answerText.ToCharArray();

    int[] answerArr = new int[answerChar.Length];
    int length = answerArr.Length;

    for(int i = 0; i < length; i++) 
      answerArr[i] = (int)Char.GetNumericValue(answerChar[i]); 

    if(answerArr[length - 1] >= 5)
      answerArr[length -1] -= 1;
      answerArr[length - 1] += 1;

    foreach(int num in answerArr)

So here’s another solution to a CodeChef problem. The problem is to take two user-generated integers on the same line(‘A’ and ‘B’), find the difference, and then make the answer incorrect but changing one of it’s integers. And finally write the incorrect answer to the console. The OCD part of my brain was not a huge fan of writing an algorithm to produce an incorrect answer to a simple math problem but I think it was overall a good exercise for the basics.

Here’s a link to the problem.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s