A. Alex and broken contest
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.

But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name.

It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita".

Names are case sensitive.

Input

The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem.

Output

Print "YES", if problem is from this contest, and "NO" otherwise.

Examples
input
Alex_and_broken_contest
output
NO
input
NikitaAndString
output
YES
input
Danil_and_Olya
output
NO

题意  是否所有名字中只出现一次

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = ;
typedef long long ll;
string a;
string b[]={"Danil","Olya","Slava","Ann","Nikita"};
int main()
{
cin>>a;
int sum=;
for(int i=;i<;i++)
{
if(a.find(b[i])!=-) //find找到子串第一次出现的位置返回下标
sum++;
if(a.rfind(b[i])!=a.find(b[i])) //rfind找到子串最后一次出现的位置返回下标
sum++;
}
if(sum>||sum==)
printf("NO\n");
else
printf("YES\n");
return ;
}
B. Nikita and string
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

One day Nikita found the string containing letters "a" and "b" only.

Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b".

Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get?

Input

The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".

Output

Print a single integer — the maximum possible size of beautiful string Nikita can get.

Examples
input
abba
output
4
input
bab
output
2
Note

It the first sample the string is already beautiful.

In the second sample he needs to delete one of "b" to make it beautiful.

解析  前缀和暴力枚举所有划分

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = 0x3f3f3f3f;
typedef long long ll;
int a[maxn],b[maxn];
char s[maxn];
int main()
{
while(scanf("%s",s)!=EOF)
{
int len=strlen(s);
a[]=b[]=;
for(int i=;i<len;i++) //一共 len 位 0~len-1
{
a[i+]=a[i]; //a[i]表示第i位之前 不包括第i位 有多少个a
b[i+]=b[i]; //b[i]表示第i位之前 不包括第i位 有多少个b
if(s[i]=='a')
a[i+]++;
else
b[i+]++;
}
int maxx=;
for(int i=;i<=len;i++) //将 len-1位 划分为成 三个区间[1,i-1],[i,j-1],[j,len-1],枚举划分情况
{
for(int j=i;j<=len;j++)
{
int now=a[i]+(b[j]-b[i])+(a[len]-a[j]); //当前情况的长度 a + b + a
maxx=max(maxx,now); //更新最优值
}
}
printf("%d\n",maxx);
}
}

C题  偶奇偶 来炸就好了 一共n+n/2次

AC代码

 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
using namespace std;
const int maxn= 1e5+;
const int maxm= 1e4+;
const int inf = ;
typedef long long ll;
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int ans=n+n/;
printf("%d\n",ans);
for(int i=;i<=n;i++)
{
if(i%==)
printf("%d ",i);
}
for(int i=;i<=n;i++)
{
if(i%==)
printf("%d ",i);
}
for(int i=;i<=n;i++)
{
if(i%==)
{
if(i+>n)
printf("%d\n",i);
else
printf("%d ",i);
}
}
}
return ;
}

最新文章

  1. Regular Expression Matching
  2. 捉襟见肘之UIView中contentMode属性
  3. 记一个由MemCached引发的性能问题
  4. [Ogre]纹理设置
  5. 会话跟踪技术——cookie
  6. Python之路【第二十一篇】:Django之Form组件
  7. ExtJs中处理时间,出现NaN-NaN-NaN的解决方式
  8. Javascript url 小逻辑
  9. pushViewController自定义动画
  10. 创建服务类PO
  11. SK-Learn 全家福
  12. maven部署项目遇到的问题
  13. System V IPC 之消息队列
  14. 【实验吧】CTF_Web_登录一下好吗?
  15. 图文详解之ZSH美化你的终端CLI
  16. leetcode 124. Binary Tree Maximum Path Sum 、543. Diameter of Binary Tree(直径)
  17. Jmeter分布式压力测试
  18. PLSQL Developer连接远程Oracle数据库
  19. Redis_常见JedisConnectionException异常分析
  20. 此文记录了我从研二下学期到研三上学期的找工历程,包括百度、腾讯、网易、移动、电信、华为、中兴、IBM八家企业的面试总结和心得--转

热门文章

  1. python模拟shell执行脚本
  2. bootstrap html页面禁止放大缩小
  3. PHP随机函数【上】
  4. 搭建和测试 Redis 主备和集群
  5. UNIX域协议(无名套接字)
  6. java 信号量Semaphore
  7. Composer创建和发送HTTP Request
  8. MySQL中各种数据类型的长度及在开发中如何选择
  9. js 闭包的用法详解
  10. C#WinCE程序(.NET Compact Framework 3.5)项目重构面向抽象设计