刚开始提交的时候,惊讶地发现竟然超时了
检查了N遍终于发现把strlen写在了for循环里,这样算算时间复杂度就n^2了
解题思路:
把B串在A串出现的位置找出来
然后单独对A串计算一下height数组,然后枚举每个位置,求可以生成的子串,再减height就可以了
#include
#include
#include
using namespace std;
#define N 100...
分类:
其他好文 时间:
2015-04-16 15:48:14
阅读次数:
237
#include #include char code[8][1 >k) &&k== '\n'); // 空行重读 if (k == -1) k = 0; else gets(s + 1); s[0] = k; return strlen(s);}voi...
分类:
其他好文 时间:
2015-04-16 13:56:45
阅读次数:
94
#include#includeconst int maxn=1000;int mul(char a[],char b[],int c[]){ int la=strlen(a); int lb=strlen(b); int lc=la+lb-1; int ta[maxn],tb[maxn]; for...
分类:
其他好文 时间:
2015-04-15 22:39:37
阅读次数:
150
#include
#include
int main(){
char temp,str[20];
int k,len,mark,flag,j;
while(scanf("%s %d",str,&k)!=EOF){
len=strlen(str);
if(k==0)
{
puts(str);
continue;
}
for(int i=0;i<len;i++...
分类:
其他好文 时间:
2015-04-15 21:34:42
阅读次数:
139
大数加法
char* MaxAdd(char *str1,char *str2){
int len1=strlen(str1);
int len2=strlen(str2);
int num1[MAX]={0};
int num2[MAX]={0};
for(int j=0,i=len1-1;i>=0;i--,j++){
num1[j]=str1[i]-'0'; //转换为int数...
分类:
其他好文 时间:
2015-04-15 13:39:29
阅读次数:
153
//strlen同功能的函数stringLength。int stringLength(char *a){ int length=0; while (a[length]!='\0') { length++; } return length;}//strcpyde 同功能函数string...
分类:
其他好文 时间:
2015-04-15 11:08:30
阅读次数:
214
#include
#include
using namespace std;
class A
{
private:
char *a;
public:
A(char *aa)
{
a = new char[strlen(aa)+1]; // strcpy(a, aa); // }
~A()
{
...
分类:
其他好文 时间:
2015-04-15 09:39:59
阅读次数:
100
【项目1-深复制体验】
(1)阅读下面的程序,补足未完成的注释
#include
#include
using namespace std;
class A
{
private:
char *a;
public:
A(char *aa)
{
a = new char[strlen(aa)+1]; //(a)这样处理的意义在于...
分类:
其他好文 时间:
2015-04-15 09:39:45
阅读次数:
132
这段代码大约是10年前写的了,一直收藏在自己的代码仓库里面,贴出来分享下。网上也有很多类似的代码,学生们用的比较多,工作中用的很少,权做参考。char* ReverseString(char* s){ char *p , *q; p = s; q = p + strlen(s) - 1; w...
分类:
编程语言 时间:
2015-04-15 09:31:01
阅读次数:
141
随便定义一个char类型字符串数组,此以char string[] = "iphone";为例。实现strlenchar string[] = "iphone"; int i = 0; while (string[i] != '\0') { i ++; } printf("%d", i...
分类:
其他好文 时间:
2015-04-15 09:28:53
阅读次数:
119