'탑코더'에 해당되는 글 1건

  1. 2008/03/05 귀차니스트 TopCoder - Tournament - Inv 2001 R1 (4)

TopCoder - Tournament - Inv 2001 R1

Algorithm/TopCoder 2008/03/05 23:45 귀차니스트

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.


  간단한 문제 였습니다. String 에 관련된 문제라 std::string 인 C++ 이 아니라 C# 쪽의 split 메소드를 사용해보았습니다. 간단하게 구현되는 문제라. 어려움은 없었습니다.

Inv 2001 R1.cs (Language : csharp)
  1. class HowEasy {
  2.  public int pointVal( string param0)
  3.  {
  4.   string [] SplitData = param0.Split( " .".ToCharArray() );
  5.   if( SplitData.Length == 0 )
  6.    return 0;
  7.   int AverageCount = 0;
  8.   for( int i = 0; i < SplitData.Length; ++i ) {
  9.    AverageCount += SplitData[ i ].Length;
  10.   }
  11.   int Point =  ( int )System.Math.Floor( ( double )( AverageCount / SplitData.Length ) );
  12.   if( Point == 3 )
  13.     return 250;
  14.   if( Point == 4 || Point == 5 )
  15.     return 500;
  16.   if( Point >= 6 )
  17.     return 1000;
  18.   return 0;
  19.  }
  20. }

ㅡ,.ㅡ 알고보니 잘못된 코드였군요.. 급하게 수정하여 올립니다.
수정버젼.cs (Language : cpp)
  1. class HowEasy
  2. {
  3.     public int pointVal(string param0)
  4.     {
  5.         int WordTotalCount = 0;
  6.         int WordCount = 0;
  7.         string[] WordArray = param0.Split(" ".ToCharArray());
  8.         for (int i = 0; i < WordArray.Length; ++i, ++WordCount)
  9.         {
  10.             string Word = WordArray[i];
  11.             int FirstIndex = Word.IndexOf('.');
  12.             int LastIndex = Word.LastIndexOf('.');
  13.             if (FirstIndex != -1 && FirstIndex != LastIndex)
  14.                 continue;
  15.             Word = Word.Replace(".", "");
  16.             bool Flag = true;
  17.             foreach (char TempChar in Word)
  18.             {
  19.                 if (!char.IsLetter(TempChar))
  20.                     Flag = false;
  21.             }
  22.             if (!Flag)
  23.                 continue;
  24.             WordTotalCount += Word.Length;
  25.         }
  26.         int Average = (WordTotalCount / (WordCount == 0 ? 1 : WordCount));
  27.         if (Average <= 3)
  28.             return 250;
  29.         else if (Average == 4)
  30.             return 500;
  31.         else if (Average >= 5)
  32.             return 1000;
  33.         return 0;
  34.     }
  35. }


P.S 승훈이횽 HDTV 카드 지르세용 +ㅅ+ ㅋㅋ 아래는 스크린샷


크리에이티브 커먼즈 라이센스
Creative Commons License
2008/03/05 23:45 2008/03/05 23:45

댓글을 달아 주세요

  1. 준호씨 2008/03/06 00:49  댓글주소  수정/삭제  댓글쓰기

    우와...
    마지막 스크린샷.. 참 깨끗하군 +_+

  2. kkamagui 2008/03/12 20:08  댓글주소  수정/삭제  댓글쓰기

    횽은 TV도 안보는데 왠 TV 카드냐 ㅋㅋ 천지 이래서 안대 ㅋㅋ