Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created March 13, 2016 06:25
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/aa85318f91fbcdc8f74d to your computer and use it in GitHub Desktop.
Save jianminchen/aa85318f91fbcdc8f74d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Gemstones
{
/*
* Gemstones
* https://www.hackerrank.com/challenges/gem-stones
*
*/
class Program
{
static void Main(string[] args)
{
string s = Console.ReadLine();
int n = Convert.ToInt16(s);
string[] sA = new string[n];
for(int i=0; i<n;i++)
{
sA[i]= Console.ReadLine();
}
Console.WriteLine(getNumberOfGemElement(sA));
}
/*
* string length >=1, <=100
* only lower-cse Latin letters 'a'-'z'
*
* string array size 1 - 100
*/
public static int getNumberOfGemElement(string[] s)
{
int len = s.Length;
int[][] countA = new int[len][];
int Size = 26;
for (int i = 0; i < len; i++ )
{
countA[i] = new int[Size];
}
for (int i = 0; i < len; i++)
{
string s1 = s[i];
foreach(char c in s1)
{
countA[i][c - 'a']++;
}
}
int number = 0;
for (int i = 0; i < Size; i++)
{
bool atLeastOneZero = false;
for (int j = 0; j < len; j++) // bug002 not i++, should be j++; spell error
{
//if (countA[i][j] == 0) // bug001 - index out of range
if (countA[j][i] == 0)
{
atLeastOneZero = true;
break;
}
}
if (!atLeastOneZero)
number++;
}
return number;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment