Check the string
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.
You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).
The first and only line consists of a string SS (1≤|S|≤5000). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.
Print "YES" or "NO", according to the condition.
aaabccc
YES
bbacc
NO
aabc
YES
Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'.
#include <stdio.h>
#include <string.h>
int main()
{
int a,b,c,flag0,flag1,flag2,flag,i,len;
char s[];
gets(s);
len=strlen(s);
a=;
b=;
c=;
flag0=;
flag1=;
flag2=;
flag=;
len=strlen(s);
for(i=; i<len; i++)
{
if(s[i]=='a')
{
if(flag1||flag2)
{
printf("NO\n");
return ;
}
a++;
flag0=;
}
else if(s[i]=='b')
{
if(!flag0||flag2)
{
flag=;
break;
}
b++;
flag1=;
}
else if(s[i]=='c')
{
if(!flag0||!flag1)
{
flag=;
break;
}
c++;
flag2=;
}
}
if(flag==)
printf("NO\n");
else if((c==a||c==b)&&(c!=&&b!=))///注意要防止出现只有a,没有其他字母的情况
printf("YES\n");
else
printf("NO\n");
return ;
}
Check the string的更多相关文章
- Check the string CodeForces - 960A
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend ...
- 10 Things Every Java Programmer Should Know about String
String in Java is very special class and most frequently used class as well. There are lot many thin ...
- Java - byte[] 和 String互相转换
通过用例学习Java中的byte数组和String互相转换,这种转换可能在很多情况需要,比如IO操作,生成加密hash码等等. 除非觉得必要,否则不要将它们互相转换,他们分别代表了不同的数据,专门服务 ...
- Meteor check
check方法用于检查参数或类型是否匹配模式. 安装check包 打开命令提示符窗口,并安装该软件包. C:\Users\Administrator\Desktop\meteorApp>mete ...
- 567. Permutation in String
Problem statement: Given two strings s1 and s2, write a function to return true if s2 contains the p ...
- list去重,String[]去重,String[]去空,StringBuffer去重,并且以','隔开,list拆分
1.// 删除ArrayList中重复元素 public static void removeDuplicate(List list) { HashSet h = new HashSet(list); ...
- 【LeetCode】字符串 string(共112题)
[3]Longest Substring Without Repeating Characters (2019年1月22日,复习) [5]Longest Palindromic Substring ( ...
- CF1494A ABC String 题解
Content 给定 \(T\) 个仅包含大写字母 A,B,C 的字符串 \(s\).问你是否能够通过将每个 A,B,C 换成 (,) 中的一个(同一个字母必须要换成同一个字符),使得最后得到的括号序 ...
- 学习AOP之透过Spring的Ioc理解Advisor
花了几天时间来学习Spring,突然明白一个问题,就是看书不能让人理解Spring,一方面要结合使用场景,另一方面要阅读源代码,这种方式理解起来事半功倍.那看书有什么用呢?主要还是扩展视野,毕竟书是别 ...
随机推荐
- ie 8在打印网页的时候打印预览是空白的
win 7专业版系统中的ie 8在打印网页的时候打印预览是空白的,打印出来也是空白的,但是用别的浏览器打印没有问题 根据您的描述,该问题主要是由于保护模式下%Temp%\Low不正常工作引起的. 建议 ...
- 献给初学者:小白该如何学习Linux操作系统
一. 选择适合自己的Linux发行版 谈到linux的发行版别,太多了,可能谁也不能给出一个准确的数字,但是有一点是能够必定的,linux正在变得越来越盛行, 面临这么多的Linux 发行版,打算从别 ...
- Python学习手册之正则表达式示例--邮箱地址提取
在上一篇文章中,我们介绍了 Python 的捕获组和特殊匹配字符串,现在我们介绍 Python 的正则表达式使用示例.查看上一篇文章请点击:https://www.cnblogs.com/dustma ...
- Python文本操作2
# list3 = [# {"name": "alex", "hobby": "抽烟"},# {"name&q ...
- Java Integer == 以及分析
Java Integer == 先看一下这段代码 Integer integer1 = 100; Integer integer2 = 100; System.out.println("in ...
- 浅显易懂的Sysnchronizd用法
<编程思想之多线程与多进程(1)——以操作系统的角度述说线程与进程>一文详细讲述了线程.进程的关系及在操作系统中的表现,这是多线程学习必须了解的基础.本文将接着讲一下Java线程同步中的一 ...
- 15-oauth2+oidc实现Server部分
1-我们使用之前项目的mvcCookieAuthSampe2进行改造 1.1 增加IdentityServer4 2-增加Config.cs文件,对IdentityServer提供相关的配置数据 u ...
- 【8086汇编-Day3】用debug做实验时的技巧与坑
Ⅰ· 无病呻吟 学一门语言,不动手实验是学不好的,在实验中不断遇坑然后解决,才有进益.所以写一下我在第一次汇编实验中的所思所想(王爽<汇编语言>第二章章末实验). Ⅱ · 实验内容 题解思 ...
- cc2541测试SimpleBLEPeripheral例程
1. 修改工程选项,去掉CC2540_MINIDK,烧写CC2541代码 2. 打开手机软件TruthBlue2_7 3. 准备看下特征值4的通信,在周期处理里面,一直读取特征值3的值,然后由特征值4 ...
- linux-flock文件锁之实际运用
vi test.sh #! /bin/bash echo "Hello World" touch test.lock #随便命名 [root@localhost ~]# flock ...