Created
March 13, 2016 06:38
-
-
Save jianminchen/cb0886705d99423a321f to your computer and use it in GitHub Desktop.
String algorithm - GemStones - using one array instead of jagged array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Solution | |
{ | |
class Solution | |
{ | |
static void Main(string[] args) | |
{ | |
long numberOfCases = Convert.ToInt64(Console.ReadLine()); | |
string alphabet = "abcdefghijklmnopqrstuvwxyz"; | |
long[] gemOccurence = new long[alphabet.Length]; | |
string currentGem; | |
long gemStones = 0; | |
for(long currentCase = 0; currentCase < numberOfCases; currentCase++) | |
{ | |
currentGem = Console.ReadLine(); | |
for(int currentAlphaChar = 0; currentAlphaChar < alphabet.Length; currentAlphaChar++) | |
{ | |
for(int currentGemChar = 0; currentGemChar < currentGem.Length; currentGemChar++) | |
{ | |
if(currentGem[currentGemChar] == alphabet[currentAlphaChar]) | |
{ | |
gemOccurence[currentAlphaChar]++; | |
break; | |
} | |
} | |
} | |
} | |
foreach(long number in gemOccurence) | |
{ | |
if(number == numberOfCases) | |
{ | |
gemStones++; | |
} | |
} | |
Console.WriteLine(gemStones); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment