1 / 4
Apr 2011

This is problem 8395. ZBROJ it´s getting me wrong answer and i watched out every detailed except the output form, the problem is little specific about what should i print, i guess that´s my error. Anyway if you find any error in it please do tell me so i can finally get this.

Thank you for your time.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            string[] s = Console.ReadLine().Split(' ');
            long a = Convert.ToInt64(s[0]); // entero a
            long b = Convert.ToInt64(s[1]); // entero b    
            char[] a1= new char [s[0].Length]; //arreglo 2da a
            int c=0,d=0; // contadores de caracteres
            char[] b1= new char [s[1].Length]; //arreglo 2da b
            string x=" "; // segundos a en casos de 5 y 6
            string y = " "; //segunda b en caso 5 y 6
            long suma1= a + b;
            long suma2;
            if (digitos5y6(a) || digitos5y6(b))
        {
        
            foreach (char i in s[0])
            {
                if (i == '5') a1[c++] = '6';
                else
                {
                    if (i == '6') a1[c++] = '5';
                    else a1[c++] = i;
                }
            }

            foreach (char j in s[1])
            {
                if (j == '5') b1[d++] = '6';
                else
                {
                    if (j == '6') b1[d++] = '5';
                    else b1[d++] = j;
                }
            }

            for (int k = 0; k < a1.Length; k++)
            {
                x += a1[k];
            }

            for (int k = 0; k < b1.Length; k++)
            {
                y += b1[k];
            }

            suma2 = Convert.ToInt64(x.Trim()) + Convert.ToInt64(y.Trim());

            if (suma1 < suma2)
            {
                string result1 = Convert.ToString(suma1);
                string result2 = Convert.ToString(suma2);
                Console.WriteLine(result1 + ' ' + result2);
            }
            else
            {
                string result1 = Convert.ToString(suma2);
                string result2 = Convert.ToString(suma1);
                Console.WriteLine(result1 + ' ' + result2);
            }
        }

        if (!digitos5y6(a) && !digitos5y6(b)) Console.WriteLine(suma1);
        Console.Read();
    }

    static bool digitos5y6(long n)
    {
        //revisa si el numero tiene digitos de 5 o 6

        bool dig = false; // si tiene dig de 5 o 6 asume no
        long r; //residuo actual del ciclo

        while (n > 0)
        {
            r = n % 10;
            if (r == 5 || r == 6) dig = true;
            n = n / 10;
        }

        return dig;

    }
}
}
  • created

    Apr '11
  • last reply

    Apr '11
  • 3

    replies

  • 315

    views

  • 2

    users

If you checked the code you can see that print the result space-separated and the min and the max sum you could get, in order.
My doubt is when you input numbers without digits of 5 and 6, those the problem print two times the result like 5or6 digits case,
or just print it once. Example output and input are very inconclusive.

You need to print two numbers every time. The problem statement is quite clear.