Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)
1 #include <bits/stdc++.h> 2 using namespace std; 3 char s[105]; 4 char p[]={"CODEFORCES"}; 5 int main() 6 { 7 cin>>s; 8 int j=0; 9 int len=strlen(s); 10 for(int i=0;i<len;i++) 11 { 12 if(s[i]==p[j]) 13 j++; 14 else break; 15 } 16 if(strncmp(s,p,10)==0||strncmp(s+len-10,p,10)==0||strncmp(s+len-10+j,p+j,10)==0) 17 { 18 printf("YES\n"); 19 return 0; 20 } 21 printf("NO\n"); 22 return 0; 23 }
substr函数写法:
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 string s; 6 cin>>s; 7 for(int i=0;i<s.length();i++) 8 { 9 for(int j=0;j<s.length();j++) 10 { 11 if(s.substr(0,i)+s.substr(j+1)=="CODEFORCES") 12 { 13 printf("YES\n"); 14 return 0; 15 } 16 } 17 } 18 printf("NO\n"); 19 return 0; 20 }
如果还有其它方法欢迎私信我!QAQ
B. Quasi Binary
A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011 — are quasibinary and numbers 2, 12, 900 are not.
You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.
The first line contains a single integer n (1 ≤ n ≤ 106).
In the first line print a single integer k — the minimum number of numbers in the representation of number n as a sum of quasibinary numbers.
In the second line print k numbers — the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.
9
9
1 1 1 1 1 1 1 1 1
32
3
10 11 11
1 #include <bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 int s[11]; 7 int k=1,maxn=0; 8 memset(s,0,sizeof(s)); 9 cin>>n; 10 while(n) 11 { 12 int a=n%10; 13 n/=10; 14 maxn=max(maxn,a); 15 for(int i=1;i<=a;i++) 16 s[i]+=k; 17 k*=10; 18 } 19 cout<<maxn<<endl; 20 for(int i=1;i<maxn;i++) 21 cout<<s[i]<<" "; 22 cout<<s[maxn]<<endl; 23 return 0; 24 }
作 者:Angel_Kitty
出 处:https://www.cnblogs.com/ECJTUACM-873284962/
关于作者:阿里云ACE,目前主要研究方向是Web安全漏洞以及反序列化。如有问题或建议,请多多赐教!
版权声明:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接。
特此声明:所有评论和私信都会在第一时间回复。也欢迎园子的大大们指正错误,共同进步。或者直接私信我
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角【推荐】一下。您的鼓励是作者坚持原创和持续写作的最大动力!
欢迎大家关注我的微信公众号IT老实人(IThonest),如果您觉得文章对您有很大的帮助,您可以考虑赏博主一杯咖啡以资鼓励,您的肯定将是我最大的动力。thx.
我的公众号是IT老实人(IThonest),一个有故事的公众号,欢迎大家来这里讨论,共同进步,不断学习才能不断进步。扫下面的二维码或者收藏下面的二维码关注吧(长按下面的二维码图片、并选择识别图中的二维码),个人QQ和微信的二维码也已给出,扫描下面👇的二维码一起来讨论吧!!!
欢迎大家关注我的Github,一些文章的备份和平常做的一些项目会存放在这里。