TopCoder HowEasy

ExpandedBlockStart.gif HowEasy
 1  #include  < string >
 2  #include  < sstream >
 3  #include  < algorithm >
 4  using   namespace  std;
 5 
 6  class  HowEasy
 7  {
 8       private :
 9          inline  bool  isValid( string   & token);
10 
11       public :
12           int  pointVal( string  problemStatement);
13  };
14 
15  const   static   string  g_LegalChars  =   " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ " ;
16 
17  bool  HowEasy::isValid( string   & token)
18  {
19 
20       if (token.empty())
21      {
22           return   false ;
23      }
24 
25      size_t pos  =  token.find_first_not_of(g_LegalChars);
26 
27       return  (pos  ==   string ::npos);
28  }
29 
30  int  HowEasy::pointVal( string  problemStatement)
31  {
32       string  buf;
33      stringstream ss(problemStatement);
34 
35       int  count  =   0 , sum  =   0 , average  =   0 ;
36       while (ss  >>  buf)
37      {
38           if (buf.length())
39          {
40               if (buf[buf.length()  -   1 ==   ' . ' )
41              {
42                  buf.erase(buf.end() - 1 );
43              }
44 
45               if (isValid(buf))
46              {
47                  count ++ ;
48                  sum  +=  buf.length();
49              }
50          }
51      }
52 
53       if (count  &&  sum)
54      {
55          average  =  sum  /  count;
56      }
57 
58       if (average  <=   3 )
59      {
60           return   250 ;
61      }
62       else   if (average  <=   5 )
63      {
64           return   500 ;
65      }
66       else
67      {
68           return   1000 ;
69      }
70  }

 

转载于:https://www.cnblogs.com/zhtf2014/archive/2010/10/19/1855324.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值