Search Here

Wednesday, September 9, 2015

UVa - 10194 - ( Football ( aka Soccer ) Solution ) [ With Solving Procedure ]

=>Try Yourself First. For help Scroll Down .

Ohh God . Thanks . After huge time of getting WA I got AC . Almost 10 times. But I don't care about it . I got AC . That's the Thing of Happiness. Now I am going to tell You how to Solve it?  Read the problem statement Very Very Carefully .

Clearance :
After reading the Problem . You got an Idea about which algorithm Should apply ?  . Yes. " Sorting " . But Sort with some Custom Condition . So what you have to do is - 


  • After taking the inputs into an array call STL " sort ( ) " and With a Comparing function Sort the Whole list as the Problem statement Said.
  • Take a Good care about Input and Output Handling System . This two suffer you a lot in solving this Problem . Read the " INPUT " Section of Problem Statement very carefully .This point suffers me a lot .
  • And keep your Head very Cool until you solve this Problem . After solving You can Dance . As I did . I solved it after 18 hours . A silly point take a time about 2-3 hours. So very careful about what you did and are doing .
Input Handing System
  • As the problem statement Stated, take a number TEST ( test cases )& N ( number of teams ).Use ' getchar() ' after taking N. Then, you have to take the Team Names . I would like to Suggest you to take this Team Names into a Map and Assign an Integer for each team. Then you have to take G( number of games played ). Again use a ' getchar()' here. Then take Game Result as a String . The run a loop from ' index = 0 ' to until finding '@' . In this loop before getting '#' take the Team Name and After getting '#' take the GN ( Number of Goals ) as integer . Then run another loop from ' index = index of '@' + 1 ' to the Length of String to take another Team's Goal Information . 
  • From the Goal's Information you will get the Winner , Looser, Tied Match, Number of Scored Goal of each Team, Number of Against Goal of each Team, Acquired Points of each Team, Number of Games each Team played .
  • As the Team Name any Character will Valid whose ASCII value id Greater than 31. That means from " Space " character of ASCII list to " 127 th Character " ( Except # and @ ) .
Algorithm Manipulation
  • As stated above a Custom Sort needed in this Problem . That's why you need a Structure Array which Contains the Parameter you need to Sort the Informations .  After creating a Structure Array Insert all the Parameters ( Name, Points, Number of Given Goals, Difference of Goals, Games Played, Number of Winning Match ) into that Array you need to Sort using " map iterator " . Then call STL " sort() " along with a " compare " function like below's :
  1.    sort(arr, arr+N, compare ); 
  • In that compare function use the condition according to You have to Sort...


Note For Lexicographical Order While Sorting :

  • As a Tie Breaker Team Names are Case Insensitive . That means , " BrAziL " and " bRaZil are the Same . You can use " strcasecmp() " function or You can use " strcmp() "after turning all letters into Uppercase OR Lowercase order .
Output Handling :
  • Output the Sorted List as you according to the Order as stated into the Output Specification . Print an Empty Line between Each test Cases .
!! Warning : Clear the Map every time . Set the memory elements of all Array ( Except Structure Array ) as 0.  Be careful about Spacing . !! Keep yourself Free from Tension . Don't Panic If You got WA . Go through on you code once and think again what you have missed.  !!


// The language of Code is Flexible to read for the Bangladeshis . I have used here " KHATI BANGLA SHOBDO " .
========================================================================================
Code :




======================================================================================================

For Critical Inputs And OutputsCheck This Critical Inputs 

=>Question or Need Help ?? Leave a Comment .

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hey ...
    { hashfound = true; continue; }
    if(!hashfound)
    {
    adi1 = adi1 +
    score[j];
    }

    - About this statement.

    See the Given Scoreline .. The Team Name & Number of Goals are Separated by only this Hash ( # )[ That means ' # ' is a Separator between Team Name & Goal Scored ] .... Let "adi1" & "adi2" is two Additional String to store two team's name . So, When if we found a Hash ' # ' then we can say that We get a Team's Name Already . And now we have to take that team's Scored_Goal.

    For example Barcelona#2@2#Real_Madrid .[ ' # ' is the separator that we have to use to take team's Name & Goal Information ]. Hope Got it .....
    For more leave a Comment .

    ReplyDelete