# Đề tài: [TopCoder] Practice Rooms => 1-Tournament => 1-Inv 2001 R1

1. \x37\x55\x32\x00
Ngày gia nhập
11 2008
Bài viết
186

## [TopCoder] Practice Rooms => 1-Tournament => 1-Inv 2001 R1

Mọi người cùng tham khảo giải quyết bài này cùng Kim với:

Problem Statement

***Note: Please keep programs under 7000 characters in length. Thank you

Class Name: HowEasy
Method Name: pointVal
Parameters: String
Returns: int

TopCoder has decided to automate the process of assigning problem difficulty
levels to problems. TopCoder developers have concluded that problem difficulty
is related only to the Average Word Length of Words in the problem statement:

If the Average Word Length is less than or equal to 3, the problem is a 250
point problem.
If the Average Word Length is equal to 4 or 5, the problem is a 500 point
problem.
If the Average Word Length is greater than or equal to 6, the problem is a 1000
point problem.

Definitions:
Token - a set of characters bound on either side by spaces, the beginning of
the input String parameter or the end of the input String parameter.
Word - a Token that contains only letters (a-z or A-Z) and may end with a
single period. A Word must have at least one letter.
Word Length - the number of letters in a Word. (NOTE: a period is NOT a letter)

The following are Words :
"ab", "ab."

The following are not Words :
"ab..", "a.b", ".ab", "a.b.", "a2b.", "."

Average Word Length - the sum of the Word Lengths of every Word in the problem
statement divided by the number of Words in the problem statement. The
division is integer division. If the number of Words is 0, the Average Word
Length is 0.

Implement a class HowEasy, which contains a method pointVal. The method takes
a String as a parameter that is the problem statement and returns an int that
is the point value of the problem (250, 500, or 1000). The problem statement
should be processed from left to right.

Here is the method signature (be sure your method is public):
int pointVal(String problemStatement);

problemStatement is a String containing between 1 and 50 letters, numbers,
spaces, or periods. TopCoder will ensure the input is valid.

Examples:

If problemStatement="This is a problem statement", the Average Word Length is
23/5=4, so the method should return 500.
If problemStatement="523hi.", there are no Words, so the Average Word Length is
0, and the method should return 250.
If problemStatement="Implement a class H5 which contains some method." the
Average Word Length is 38/7=5 and the method should return 500.
If problemStatement=" no9 . wor7ds he8re. hj.." the Average Word Length is 0,
and the method should return 250.
Definition

Class:
HowEasy
Method:
pointVal
Parameters:
string
Returns:
int
Method signature:
int pointVal(string param0)
(be sure your method is public)

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
Đã được chỉnh sửa lần cuối bởi rox_rook : 13-11-2008 lúc 09:19 AM.

2. Thành viên chính thức
Ngày gia nhập
03 2009
Bài viết
86
C++ Code:
1. #include <iostream>
2. #include <string>
3. using namespace std;
4.
5. class HowEasy
6. {
7. private:
8.
9. public:
10.     const int pointVal(const string &p) const
11.     {
12.         int i = 0, j = 0,k = 0;
13.         string s;
14.         int length = 0;
15.         int number = 0;
16.
17.         // first letter
18.         if ((p[0] <= 'z' && p[0] >= 'a')||(p[0] <= 'Z' && p[0] >= 'A'))
19.             s += p[0];
20.         // others letter and period
21.         for (i = 1; i <= p.size(); ++i)
22.         {
23.             if (((p[i] <= 'z' && p[i] >= 'a')||(p[i] <= 'Z' && p[i] >= 'A')) && (((p[i - 1] <= 'z' && p[i - 1] >= 'a')||(p[i - 1] <= 'Z' && p[i - 1] >= 'A'))|| p[i - 1] == ' '))
24.                 s += p[i];
25.             else if (p[i] == '.' && ((p[i] <= 'z' && p[i] >= 'a')||(p[i] <= 'Z' && p[i] >= 'A')))
26.             {
27.                 s += p[i];
28.                 j = 1;
29.             }
30.             else if (p[i] == ' '||p[i] =='\0')
31.             {
32.                 if(s.size() >= 1)
33.                     ++ number;
34.                 if (j == 1)
35.                     length += s.size() - 1;
36.                 else
37.                     length += s.size();
38.
39.                 // reset
40.                 s = "";
41.                 j = 0;
42.             };
43.         };
44.
45.         k = length/number;
46.         if (k <= 3)
47.             return 250;
48.         else if (k <= 5)
49.             return 500;
50.         else
51.             return 1000;
52.     };
53. };
54.
55. int main (void)
56. {
57.     HowEasy a;
58.     cout << a.pointVal("abc");
59.     return 1;
60. };

#### Quyền hạn của bạn

• Bạn không thể gửi đề tài mới
• Bạn không thể gửi bài trả lời
• Bạn không thể gửi các đính kèm
• Bạn không thể chỉnh sửa bài viết của bạn