Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/cb0886705d99423a321f to your computer and use it in GitHub Desktop.
Save jianminchen/cb0886705d99423a321f to your computer and use it in GitHub Desktop.
String algorithm - GemStones - using one array instead of jagged array
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