• Topcoder SRM654 DIV2 250 SquareScoresDiv2


    题意:给你一个字符串,算它的值,单个值为1  连续的值为累加和。

    解题思路:水

    解题代码:

      

      1 // BEGIN CUT HERE
      2 /*
      3 
      4 */
      5 // END CUT HERE
      6 #line 7 "SquareScoresDiv2.cpp"
      7 #include <cstdlib>
      8 #include <cctype>
      9 #include <cstring>
     10 #include <cstdio>
     11 #include <cmath>
     12 #include <algorithm>
     13 #include <vector>
     14 #include <string>
     15 #include <iostream>
     16 #include <sstream>
     17 #include <map>
     18 #include <set>
     19 #include <queue>
     20 #include <stack>
     21 #include <fstream>
     22 #include <numeric>
     23 #include <iomanip>
     24 #include <bitset>
     25 #include <list>
     26 #include <stdexcept>
     27 #include <functional>
     28 #include <utility>
     29 #include <ctime>
     30 using namespace std;
     31 
     32 #define PB push_back
     33 #define MP make_pair
     34 
     35 #define REP(i,n) for(i=0;i<(n);++i)
     36 #define FOR(i,l,h) for(i=(l);i<=(h);++i)
     37 #define FORD(i,h,l) for(i=(h);i>=(l);--i)
     38 
     39 typedef vector<int> VI;
     40 typedef vector<string> VS;
     41 typedef vector<double> VD;
     42 typedef long long LL;
     43 typedef pair<int,int> PII;
     44 
     45 
     46 class SquareScoresDiv2
     47 {
     48         public:
     49         int getscore(string s)
     50         {
     51            int t = 1 ; 
     52            int sum = 0 ; 
     53            int len = s.size();
     54            for(int i = 1 ;i < s.size(); i ++)
     55            {
     56                 if(s[i] != s[i-1])
     57                 {
     58                   int tsum = 0 ; 
     59                    for(int j = 1; j <= t; j ++ )
     60                    {
     61                      tsum += j ;
     62                    }
     63                    sum += tsum  ;
     64                    t = 1 ;
     65                 }else{
     66                   t ++ ; 
     67                 }
     68            }
     69            int tsum = 0 ; 
     70            for(int j = 1; j <= t ;j ++)
     71            {
     72             tsum += j ; 
     73            }
     74            return sum + tsum ; 
     75         }
     76         
     77 // BEGIN CUT HERE
     78     public:
     79     void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
     80     private:
     81     template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '"' << *iter << "","; os << " }"; return os.str(); }
     82     void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "	Expected: "" << Expected << '"' << endl; cerr << "	Received: "" << Received << '"' << endl; } }
     83     void test_case_0() { string Arg0 = "aaaba"; int Arg1 = 8; verify_case(0, Arg1, getscore(Arg0)); }
     84     void test_case_1() { string Arg0 = "zzzxxzz"; int Arg1 = 12; verify_case(1, Arg1, getscore(Arg0)); }
     85     void test_case_2() { string Arg0 = "abcdefghijklmnopqrstuvwxyz"; int Arg1 = 26; verify_case(2, Arg1, getscore(Arg0)); }
     86     void test_case_3() { string Arg0 = "p"; int Arg1 = 1; verify_case(3, Arg1, getscore(Arg0)); }
     87     void test_case_4() { string Arg0 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; int Arg1 = 5050; verify_case(4, Arg1, getscore(Arg0)); }
     88 
     89 // END CUT HERE
     90 
     91 };
     92 
     93 // BEGIN CUT HERE
     94 int main()
     95 {
     96         SquareScoresDiv2 ___test;
     97         ___test.run_test(-1);
     98         return 0;
     99 }
    100 // END CUT HERE
    View Code
    没有梦想,何谈远方
  • 相关阅读:
    session
    .net core 入坑经验
    .net core 入坑经验
    .net core 入坑经验
    一段刚刚出炉的CSV文件转换为DataTable对象的代码
    Github的一般用法
    SQLite简单使用记录
    一次SQLServer数据库宕机问题
    B样条基函数(cubic spline basis)
    matlab使用
  • 原文地址:https://www.cnblogs.com/zyue/p/4368946.html
Copyright © 2020-2023  润新知