zoukankan      html  css  js  c++  java
  • Codeforces 266A Stones on the Table

    Stones on the Table
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.

    Input

    The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table.

    The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals "R", if the i-th stone is red, "G", if it's green and "B", if it's blue.

    Output

    Print a single integer — the answer to the problem.

    Sample test(s)
    input
    3 RRG
    output
    1
    input
    5 RRRRR
    output
    4
    input
    4 BRBG
    output
    0


    今天终于能上去Codeforces了,激动好久(之前还以为遭到方校长封杀,校园网根本上不去呢……

    于是开始在DP里找水题做,可这过得人数最多的一道题,真没看出来跟DP有啥关系……

    大水题就是把相邻且相同的字母删到只剩一个,直接上代码吧……

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 
     5 using namespace std;
     6 
     7 int len;
     8 char s[100];
     9 
    10 int main()
    11 {
    12     while(scanf("%d",&len)==1)
    13     {
    14         int ans=0;
    15         getchar();
    16         gets(s);
    17         for(int i=0;i<len;i++)
    18         {
    19             int j;
    20             for(j=i+1;j<len&&s[i]==s[j];j++)
    21                 ans++;
    22             i=j-1;
    23         }
    24         printf("%d
    ",ans);
    25     }
    26 
    27     return 0;
    28 }
    [C++]
  • 相关阅读:
    常用浏览器内核
    点透问题及解决
    移动端click延迟和tap事件
    CommandoVM-虚拟机映像文件 | VM打开直接用
    Crackme006
    CrackMe005-下篇 | 逆向破解分析 | 160个CrackMe(视频+图文)深度解析系列
    拼多多被薅-谈网络安全中最后的屏障
    一次VB汇编中看-溢出计算
    CM005-逆向分析过程(上篇)
    CrackMe-005全破详解(图文+源码)--上篇
  • 原文地址:https://www.cnblogs.com/lzj-0218/p/3234138.html
Copyright © 2011-2022 走看看