TopCoder problem "SendingCards" used in TCHS SRM 48 (Division I Level One)



Problem Statement

    

When a major holiday is approaching, some people send cards to their friends. Unfortunately, some people forget a few of their friends, and are embarrassed to receive a card from them without having sent one. So, they follow by sending a card to those who were forgotten the first time around.

You are given a String[] friends, where the j-th character of the i-th element is a 'Y' or 'N', indicating whether or not person i sent a card to person j.

You are to return an int indicating the number of cards that get sent after the fact, when people realize they have forgotten one or more of their friends.

 

Definition

    
Class:SendingCards
Method:howMany
Parameters:String[]
Returns:int
Method signature:int howMany(String[] friends)
(be sure your method is public)
    
 

Notes

-Character i of element i of friends will always be 'N'. In other words, it can be assumed that a person never sends a card to himself.
 

Constraints

-friends will contain between 1 and 50 elements, inclusive.
-Each element of friends will contain exactly N characters, where N is the number of elements in friends.
-Each character of each element of friends will be 'Y' or 'N'.
-Character i of element i of friends will always be 'N'.
 

Examples

0)
    
{"NY",
 "NN"}
Returns: 1
Person 0 sent a card to person 1 initially. Since person 1 did not initially send a card to person 0, he sends one after the fact.
1)
    
{"NYY",
 "NNY",
 "NNN"}
Returns: 3
Person 0 sent a card to both of his friends. Person 1 sent a card to person 2, but not to person 0 (whom he did receive a card from). Person 2 received 2 cards even though he didn't send any initially. Person 1 then has to send a card to person 0. Person 2 sends a card to both person 0 and person 1, for a total of three cards sent.
2)
    
{"NYY",
 "NNN",
 "NNN"}
Returns: 2
Only person 0 sent out cards initially. Both of his friends then reciprocate.
3)
    
{"NYN",
 "YNN",
 "NNN"}
Returns: 0
Person 0 and 1 mutually sent cards initially. Person 2 did not send or receive any cards. Thus, nobody received a card from anyone whom they did not originally send a card.
4)
    
{"NNNN",
 "NNNN",
 "NNNN", 
 "NNNN"}
Returns: 0
There are four friends. However, none felt the need to send a Christmas card, and so none feel guilty either.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8456

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10807&pm=8456

Writer:

timmac

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Brute Force, Simple Search, Iteration