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.
The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100— the name of the problem.
Print "YES", if problem is from this contest, and "NO" otherwise.
Alex_and_broken_contest
NO
NikitaAndString
YES
Danil_and_Olya
NO
那几个人名只出现一个人名出现一次,这个是题意杀,是真烦
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); string s; cin>>s; int ans=0; for(int i=0; s[i]; i++) { if(s.find("Danil",i)==i)ans++; if(s.find("Olya",i)==i)ans++; if(s.find("Slava",i)==i)ans++; if(s.find("Ann",i)==i)ans++; if(s.find("Nikita",i)==i)ans++; } printf("%s",(ans==1)?"YES":"NO"); return 0; }
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?
The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b".
Print a single integer — the maximum possible size of beautiful string Nikita can get.
abba
4
bab
2
It the first sample the string is already beautiful.
In the second sample he needs to delete one of "b" to make it beautiful.
dp一下吧,统计ab个数,改改数据又是一道新题,因为n^2的做法不优秀
#include <bits/stdc++.h> using namespace std; char a[5010]; int B[5010],A[5010]; int main() { scanf("%s",a+1); int l=strlen(a+1); for(int i=1; i<=l; i++) { A[i]=A[i-1]; B[i]=B[i-1]; if(a[i]=='a') A[i]++; else B[i]++; } int ans=0; for(int i=0; i<=l; i++) for(int j=i; j<=l; j++) ans=max(ans,A[l]+A[i]-A[j]+B[j]-B[i]); printf("%d",ans); return 0; }
c代表只有一串a的长度,b代表只有一串啊和b的最长长度,a代表一串a一串b再一串a的最大长度
#include <bits/stdc++.h> using namespace std; char s[5010]; int main() { scanf("%s",s+1); int a=0,b=0,c=0; for(int i=1; s[i]; i++) { if(s[i]=='a') a++,c++; else b++; a=max(a,b); b=max(c,b); } printf("%d",a); return 0; }
这个c拿来构造一波吧
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); int n; cin>>n; cout<<(n/2)*2+(n+1)/2<<' '; for(int i=2;i<=n;i+=2) cout<<i<<" "; for(int i=1;i<=n;i+=2) cout<<i<<" "; for(int i=2;i<=n;i+=2) cout<<i<<" "; return 0; }