zoukankan      html  css  js  c++  java
  • JustOj 2038: 叶神的字符串

    题目描述

    众所周知,ACS协会会长叶神学习特别好,算法能力也强,作为一个弱渣的大豪哥特别崇拜叶神,觉得‘Y’‘S’这两个字符特别厉害,所以大豪哥的一个键盘上就只有Y,S两个键,大豪哥用这个键盘打出了一个字符串s,但是他特别的不满意,所以他想改变字符串s中的一个字符(也可以不改变),使得字符串s中可以截取出最大数量的“YS”

    输入

    多组输入至文件结尾。
    每组测试数据输入一串由'Y','S'组成的字符串。(字符串长度最多为10000)

    输出

    输出至多一次修改后最多有多少个“YS”

    样例输入
    YYYS
    样例输出
    2

    题解:查找YS的字符片段,查到了就把它置为空格,遍历完了一遍以后,最后在查找有没有不是空格但是前后相同的转发片段
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <vector>
     6 #include <cstdlib>
     7 #include <iomanip>
     8 #include <cmath>
     9 #include <ctime>
    10 #include <map>
    11 #include <set>
    12 #include <queue>
    13 using namespace std;
    14 #define lowbit(x) (x&(-x))
    15 #define max(x,y) (x>y?x:y)
    16 #define min(x,y) (x<y?x:y)
    17 #define MAX 100000000000000000
    18 #define MOD 1000000007
    19 #define pi acos(-1.0)
    20 #define ei exp(1)
    21 #define PI 3.141592653589793238462
    22 #define INF 0x3f3f3f3f3f
    23 #define mem(a) (memset(a,0,sizeof(a)))
    24 typedef long long ll;
    25 ll gcd(ll a,ll b){
    26     return b?gcd(b,a%b):a;
    27 }
    28 const int N=1e6+10;
    29 const int mod=1e9+7;
    30 int main()
    31 {
    32     string s;
    33     while(cin>>s){
    34         int t=0;
    35         for(int i=0;i<s.length();i++){
    36             if(s[i]=='Y'&&s[i+1]=='S'){
    37                 t++;
    38                 s[i]=s[i+1]=' ';
    39             }
    40         }
    41         for(int i=0;i<s.length();i++){
    42             if(s[i]!=' '&&s[i]==s[i+1]){
    43                 t++;
    44                 break;
    45             }
    46         }
    47         cout<<t<<endl;
    48     }
    49     return 0;
    50 }
  • 相关阅读:
    Codeforces 371D Vessels
    HDU1272小希的迷宫–并查集
    golang:exported function Script should have comment or be unexported
    动态规划--0,1背包问题(再也不怕类似背包问题了)
    golang数据结构之稀疏数组
    向github中已创建好的repository提交文件
    java(二)变量
    使用Git上传文件到github
    java(一)基础知识
    pytorch--基础类型之间的转换
  • 原文地址:https://www.cnblogs.com/wydxry/p/7273956.html
Copyright © 2011-2022 走看看