Advertisement
GraionDilach

Számjegyesdi fájlosan

Feb 21st, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] DasArray = new int[1];
  14.             int ArrayCount = 0;
  15.  
  16.             bool ell;
  17.             int Current = 0;
  18.             bool superell = true;
  19.             string Test;
  20.  
  21.             StreamReader TestStream = new StreamReader(@"c:\test.txt");
  22.             while ((Test = TestStream.ReadLine()) != null)
  23.             {
  24.                 if ((Current = Convert.ToInt32(Test)) != 0)
  25.                 {
  26.                     Array.Resize(ref DasArray, ArrayCount + 1);
  27.                     DasArray[ArrayCount] = Current;
  28.                     ArrayCount++;
  29.                 }
  30.             }
  31.  
  32.             if (Current == 0 && ArrayCount == 0)
  33.             { superell = false; }
  34.  
  35.             if (superell)
  36.             {
  37.                 for (int i = 0; i < DasArray.Length; i++)
  38.                 {
  39.                     int Sum;
  40.                     ell = HashNumber(out Sum, DasArray[i]);
  41.                     if (ell)
  42.                     {
  43.                         Console.WriteLine("A " + (i + 1) + ". szám számjegyazonossággal rendelkezik, számjegyösszege " + Sum + ".");
  44.                     }
  45.                     else
  46.                     {
  47.                         Console.WriteLine("A " + (i + 1) + ". szám számjegyazonossággal nem rendelkezik, számjegyösszege " + Sum + ".");
  48.                     }
  49.  
  50.                 }
  51.             }
  52.         }
  53.  
  54.         static bool HashNumber(out int Sum, int Input)
  55.         {
  56.             int[] Numbers = new int[10];
  57.             Sum = 0;
  58.  
  59.             do
  60.             {
  61.                 int Temp = Input % 10;
  62.                 Sum = Sum + Temp;
  63.                 Numbers[Temp]++;
  64.                 Input = Input / 10;
  65.  
  66.             } while (Input > 0);
  67.  
  68.             for (int i = 0; i < Numbers.Length; i++)
  69.             {
  70.                 if (Numbers[i] > 1)
  71.                 {
  72.                     return true;
  73.                 }
  74.  
  75.  
  76.             }
  77.  
  78.             return false;
  79.         }
  80.  
  81.  
  82.  
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement