(本程序功能:字符串A中找出包含字符串B中所有字符的位置并输出) 在使用全局变量m的时候,输出错误的结果,而用下面局部变量M就没问题。
来源:互联网 发布:linux php搭建网站教程 编辑:程序博客网 时间:2024/04/19 09:42
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
int print_str_connection_order(char *source_str,char *destination_str,int source_str_length,int destination_str_length,int *save_str_array,int save_array_str_start,int source_str_start,int destination_str_start)
{
char *s=source_str;
char *d=destination_str;
int as=save_array_str_start,ss=source_str_start,ds=destination_str_start,sl=source_str_length,dl=destination_str_length;
int *array=save_str_array;
for(int i=ds;i<dl;i++)
{
for(int j=ss;j<sl;j++)
{
if(s[j]==d[i])
{
array[as]=j;
as+=1;
}
}
}
return as;
}
int main()
{
// char a='@';
// printf("%d",a);
//不能用全局变量 int m;
char s1[]="abcdefgabc";
char s2[]="abc";
int *arr;
int count=print_str_connection_order(s1,s2,strlen(s1),strlen(s2),arr,0,0,0);
for(int m=0;m<count;m++)
{
cout<<arr[m]<<"\t";;
}
cout<<endl;
// cout<<arr[0]<<"\t"<<arr[1]<<"\t"<<arr[2]<<"\t"<<arr[3]<<endl;
//cout<<*arr<<"\t"<<*(arr+1)<<"\t"<<*(arr+2)<<endl;
//数组溢出 cout<<arr[8]<<endl;
system("pause");
return 0;
}
#include<iostream>
#include<stdlib.h>
using namespace std;
int print_str_connection_order(char *source_str,char *destination_str,int source_str_length,int destination_str_length,int *save_str_array,int save_array_str_start,int source_str_start,int destination_str_start)
{
char *s=source_str;
char *d=destination_str;
int as=save_array_str_start,ss=source_str_start,ds=destination_str_start,sl=source_str_length,dl=destination_str_length;
int *array=save_str_array;
for(int i=ds;i<dl;i++)
{
for(int j=ss;j<sl;j++)
{
if(s[j]==d[i])
{
array[as]=j;
as+=1;
}
}
}
return as;
}
int main()
{
// char a='@';
// printf("%d",a);
//不能用全局变量 int m;
char s1[]="abcdefgabc";
char s2[]="abc";
int *arr;
int count=print_str_connection_order(s1,s2,strlen(s1),strlen(s2),arr,0,0,0);
for(int m=0;m<count;m++)
{
cout<<arr[m]<<"\t";;
}
cout<<endl;
// cout<<arr[0]<<"\t"<<arr[1]<<"\t"<<arr[2]<<"\t"<<arr[3]<<endl;
//cout<<*arr<<"\t"<<*(arr+1)<<"\t"<<*(arr+2)<<endl;
//数组溢出 cout<<arr[8]<<endl;
system("pause");
return 0;
}
- (本程序功能:字符串A中找出包含字符串B中所有字符的位置并输出) 在使用全局变量m的时候,输出错误的结果,而用下面局部变量M就没问题。
- 编写程序,删除字符串中指定位置m上开始的n个字符,并输出删除后的字符串。
- Scala对于字符串的筛选 --eg“a,v,b,nj,m”找出来不包含m的字符
- 19.在字符串数组中找出给定的字符串并输出其位置
- 输出字符串中字符的所有排列
- 比较两个字符串A和B,确定A中是否包含B中所有的字符。
- 比较两个字符串A和B,确定A中是否包含B中所有的字符。
- C#找出字符串中某一字符的所有位置
- 49.给定的字符串中找出小于97的字符存入数组中并输出
- 4.写一个控制台应用程序,接收一个长度大于3的字符串,完成下列功能: 1)输出字符串的长度。 2)输出字符串中第一个出现字母a的位置。 3)在字符串的第3个字符后面插入子串“hello”,输出新字符串。 4)将字符串“hello”替换为“me”,输出
- 找出字符串中最长的数字子串并指出位置长度,输出。
- 【C语言】在字符串中找出第一个只出现一次的字符。如输入“abaccdeff”,则输出’b’
- 【C语言】在字符串中找出第一个只出现一次的字符,输入“abaccdeff”,则输出'b'
- 在字符串中找出第一个只出现一次的字符,例如:输入abaccdeff,则输出b
- 给出字符串a和字符串b,保证b是a的一个子串,请你输出b在a中第一次出现的位置
- 根据输入m数据,找出str的m个字符的所有字符串
- 下面程序是在三个字符串中找出最小的
- 从字符串A中删除字符串B的所有字符
- Groovy&&Java往Oracle的CLOB字段中插值
- convert RGB image to a 2x2 [GR;BG] Bayer pattern
- android window类解析
- 日货名单大全,坚决长期抵制日货,团结行动起来
- android Monkey的使用
- (本程序功能:字符串A中找出包含字符串B中所有字符的位置并输出) 在使用全局变量m的时候,输出错误的结果,而用下面局部变量M就没问题。
- 基于小波变换的图像去噪
- [转]“校园小计划”招生忽悠仍在继续
- make-002: eclipse下autoconf和automake
- 斗地主AI算法实现 一(拆牌)
- 最简单的xml操作方式!
- 多媒体基础知识--编解码学习
- 梯度计算
- DS18B20 驱动