| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1045 人关注过本帖
标题:试了很多次都不行·········why
取消只看楼主 加入收藏
checoly
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2004-9-11
收藏
 问题点数:0 回复次数:2 
试了很多次都不行·········why

编函数int find(char s[],char t[]),该函数在字符串s中查找字符串t,如果找到,则返回字符串t在字符串s中的位置(整数值);否则返回-1。注意:用数组方式及两重循环来实现该函数。仅在find的花括号中填写若干句。

#include<iostream.h> #include<string> int find(char s[],char t[]); const int MAXLINE=256; int main() {char source[MAXLINE],target[MAXLINE]; cout<<"Please in put a string for searching:\n"; cin.getline(source,MAXLINE); cout<<"Please input a string you want to find:\n"; cin.getline(target,MAXLINE); int intPos=find(source,target); if(inPos>=0) cout<<"Find it.The target string is at index"<<inpos<<"of the source string\n"; else cout <<"Not finding it.\n"; return 0; } int find(char s[],char t[]) { }

试了很多次都不成功,又没有答案·········

帮帮忙········

呵呵·······

搜索更多相关主题的帖子: why 
2004-09-17 20:58
checoly
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2004-9-11
收藏
得分:0 

这是我最后写的····

乱七八糟····唉······

#include<iostream.h> #include<string> int find(char s[],char t[]); const int MAXLINE=256; int main() {char source[MAXLINE],target[MAXLINE]; cout<<"Please in put a string for searching:\n"; cin.getline(source,MAXLINE); cout<<"Please input a string you want to find:\n"; cin.getline(target,MAXLINE); int intPos=find(source,target); if(intPos>=0) cout<<"Find it.The target string is at index"<<intPos<<"of the source string\n"; else cout <<"Not finding it.\n"; return 0; } int find(char s[],char t[]) {int len1=strlen(s),len2=strlen(t); int i=0,count=0; char *p=t; for(int j=0;j<len2;j++) {for(;i<len1;i++) if(char s[i]==p) count++;

} p++; return (i-count+1); else return -1; }


2004-09-17 21:00
checoly
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2004-9-11
收藏
得分:0 

无论输入什么,都说找不到喔·······

而且他说用2重循环········


2004-09-18 18:23
快速回复:试了很多次都不行·········why
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014555 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved