恒邪

2014年3月18日 #

string.find()函数用法

摘要: 1.返回字符串s1在s中的位置,如果没有找到,则返回-1#include #include using namespace std;int main(){ string s="what are you dong"; string s1="are"; int position; position=s.find(s1); if(position==-1) cout#include using namespace std;int main(){ string s="hahahaha"; string s1="a"; in 阅读全文

posted @ 2014-03-18 19:51 恒邪 阅读(1766) 评论(0) 推荐(0) 编辑

substr(),strstr()函数用法

摘要: #include #include using namespace std;int main(){ string s="abcdefg"; string s1=s.substr(2,6);//s1为字符串s起始位置为2,长度为6的一段字符串,注意s的位置是从0开始的,即‘a'的位置为0 cout#include using namespace std;int main(){ char a[]="my dream will come true"; char *p; p=strstr(a,"dream");//a中找到字符串dre 阅读全文

posted @ 2014-03-18 19:21 恒邪 阅读(240) 评论(0) 推荐(0) 编辑

[蓝桥杯历届题目] 正六面体染色 ; 取字母组成串

摘要: 1. 正六面体染色正六面体用4种颜色染色。共有多少种不同的染色样式?要考虑六面体可以任意旋转、翻转。参考答案:240解答:Burnside引理,正方体涂色问题(n^6+3*n^4+12*n^3+8*n^2)/24 把n=4d带入公式就行了。2.取字母组成串A B C D中取5次,每个字母都可以重复取出,形成一个串。现在要求,串中A出现的次数必须为偶数(0次也算偶数)。求可以形成多少种可能的串。参考答案:528代码:#include using namespace std;char a[4]={'A','B','C','D'};in 阅读全文

posted @ 2014-03-18 10:22 恒邪 阅读(401) 评论(0) 推荐(0) 编辑

[练习] 求组合数

摘要: C(m,n) 从m个中取出n个,问一共有多少种情况。代码:#include using namespace std;int c(int m,int n){ if(n==0) return 1; if(m<n) return 0; return c(m-1,n)+c(m-1,n-1);}int cc(int m,int n){ int cmn=1; for(int i=0;i<n;i++) { cmn=cmn*(m-i)/(i+1); } return cmn;}int main(){ cout<<c... 阅读全文

posted @ 2014-03-18 09:53 恒邪 阅读(153) 评论(0) 推荐(0) 编辑

导航