Officially settled in the blog circle and posted some previous exercises on topcoder. If you are interested in algorithms and STL, you can read them :)

Source: Internet
Author: User

First introduce the topcoder website (http://www.topcoder.com/tc), which is a gathering of programmers around the worldAlgorithmIf you are interested in Engineering Development, you can get the information you are interested in. The most famous here is its competitions arena, which is a cool programming competitive platform using applet, compared with the ACM algorithm platform in China (PKU judge online, zju, etc.), I prefer the former: You need to install JDK 1.4x or later to run thisProgramIf your machine does not have JDK installed, after you click to enter, you only need to follow the prompts step by step to complete the entire process from download to installation.

Topcoder uses three languagesProgramming Language: C ++ (STL), C #, Java, you can choose the language you are familiar with to start your competition. I learned about this website when I participated in Google Code jam at the end of last year. I used to practice algorithms only in PKU judge online (http://acm.pku.edu.cn/JudgeOnline/) and then started to come, you can access experts from all over the world.
Well, after so much nonsense, let's get started with the topcoder, introduce the real questions of SRM (single round match) on topcoder, and attach my personal answers to each question. you can also express your own opinions.

Source: srm250 div2
Level: 250 points
Question:
Problem Statement

An electronics manufacturer has called you in to make a program to decode resistor color codes. you are given a vector <string> code containing three elements corresponding to the first three color bands on a resistor. return the # of Ohms the resistor represents. the first two bands of resistors represent the value, while the third is a multiplier, as shown in the following chart:
Color: Value: multiplier:

Black 0 1
Brown 1 10
Red 2 100
Orange 3 1,000
Yellow 4 10,000
Green 5 100,000
Blue 6 1,000,000
Violet 7 10,000,000
Gray 8 100,000,000
White 9 1,000,000,000
For example if you are given {"yellow", "Violet", "Red"}, you wowould return 4700.
Definition

Class:
Colorcode
Method:
Getohms
Parameters:
Vector <string>
Returns:
Long long
Method signature:
Long long getohms (vector <string> code)
(Be sure your method is public)

Notes
-
Actual resistors can have a 4th and even a 5th band representing the tolerance, and the amount the value might change in 1,000 hours of use, respectively, but for our purposes we will only deal with the first three bands.
Constraints
-
Code consists of 3 elements each containing one of the Color Words above, all in lower case.
Examples
0)


{"Yellow", "Violet", "Red "}
Returns: 4700
The example from the problem statement.
1)


{"Orange", "Red", "blue "}
Returns: 32000000

2)


{"White", "White", "White "}
Returns: 99000000000
The maximum possible.

/* This question is the lowest score in this SRM. That is to say, it should be the simplest question. Here we will talk about the skills for doing the question. Generally, many people prefer to start from the lowest score, but in fact, if you want to promote, it may be safer to select a question with a higher score (Make sure you do the right). Low-score questions can only be spelled out at a speed. After all, it takes only one hour, after you finish low-score questions, it will be difficult to have time for high scores. If someone makes a high-score question, even if it takes 59 minutes, then the actual score will still be higher than you. well, let's get down to the truth. This question is actually very simple. It is to find a resistance value, which corresponds to different values according to the color code. The first two are the actual resistance values, and the third is the multiplier, the returned result is the resistance value * multiplier. myCodeAs follows */

 

# Include < Iostream >
# Include < String >
# Include < Stdio. h >
# Include < Vector >
# Include < Set >
# Include < Map >
# Include < Algorithm >

Using   Namespace STD;

Enum Ecolor
{
Black,
Brown,
Red,
Orange,
Yellow,
Green,
Blue,
Violet,
Gray,
White
} ;

Const   Long   Long Multier [ 10 ] =   {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000} ;

Class Colorcode
{
Public :
Ecolor color;
Long   Long Curohms;

Public :

Long   Long Getohms (vector < String > Code)
{
Curohms =   0 ;
For ( Int I = 0 ; I < Code. Size (); I ++ )
{
If (I = 0 )
Curohms =   10 * Getcolorvalue (code [ 0 ]);
Else   If (I = 1 )
Curohms + = Getcolorvalue (code [ 1 ]);
Else Curohms * = Multier [getcolorvalue (code [ 2 ])];
}
Return Curohms;
}

Int Getcolorvalue ( String CSTR)
{
If (CSTR [ 0 ] = ' B ' )
{
If (CSTR. Compare ( " Black " ) = 0 )
Return   0 ;
Else   If (CSTR. Compare ( " Brown " ) = 0 )
Return   1 ;
Else   If (CSTR. Compare ( " Blue " ) = 0 )
Return   6 ;

}
Else   If (CSTR [ 0 ] = ' G ' )
{
If (CSTR. Compare ( " Green " ) = 0 )
Return   5 ;
Else   If (CSTR. Compare ( " Gray " ) = 0 )
Return   8 ;
}
Else   If (CSTR. Compare ( " Red " ) = 0 )
Return   2 ;
Else   If (CSTR. Compare ( " Orange " ) = 0 )
Return   3 ;
Else   If (CSTR. Compare ( " Yellow " ) = 0 )
Return   4 ;
Else   If (CSTR. Compare ( " Viotlet " ) = 0 )
Return   7 ;
Else   If (CSTR. Compare ( " White " ) = 0 )
Return   9 ;
Else   Return   - 1 ;

}
} ;

It was very simple. It took me about 10 minutes to finish this question. I believe you can be faster than me :)
Next, I will continue to introduce the points question of this SRM :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.