minnera

ctci-making-anagrams

Sep 28th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. //https://www.hackerrank.com/challenges/ctci-making-anagrams
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. class Solution {
  8.  
  9.     static void Main(String[] args) {
  10.         string a = Console.ReadLine();
  11.         string b = Console.ReadLine();
  12.        
  13.         int aSize = a.Length;
  14.         int bSize = b.Length;
  15.        
  16.         //a = 97, z = 122
  17.         int[] abcFirst = new int[26];
  18.         int[] abcSecond = new int[26];
  19.         //a -> 0, z -> 25
  20.         //x-97
  21.         for(int i = 0; i < 26; i++){
  22.             abcFirst[i] = 0;
  23.             abcSecond[i] = 0;
  24.         }
  25.         for(int i = 0; i < aSize; i++){
  26.             abcFirst[a[i]-97]++;
  27.         }
  28.        
  29.         for(int i = 0; i < bSize; i++){
  30.             abcSecond[b[i]-97]++;
  31.         }
  32.        
  33.         int deletedNumbers = 0;
  34.         for(int i = 0; i < 26; i++){
  35.             if((abcFirst[i] - abcSecond[i]) != 0){
  36.                 deletedNumbers += Math.Abs(abcFirst[i] - abcSecond[i]);
  37.             }
  38.         }
  39.         Console.WriteLine(deletedNumbers);
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment