Problem:
Given number of broken keyboard keys and a string. Find how many keys need to be repair to type this string
Input Format:
Broken keys without any spacesString to be typed
Output Format:
Number of keys which need to be repaired
Number of keys which need to be repaired
Constraints:
none
none
Sample Input
aspzq
happiness
happiness
Sample Output:
3
3
Explanations:
keys a,s and p need to be repaired
keys a,s and p need to be repaired
Solution:
@br=split("",$n);
$len=@br;
$count=0;
chomp($str=<STDIN>);
@arr=split("",$str);
$len1=@arr;
for($j=0;$j<$len;$j++)
{
if($str =~ /$br[$j]/)
{
$count++;
}
}
print "$count";
Tips:
To type p two times, key which need to repaired is key p, so count will not be doubled.
No comments:
Post a Comment