《c程序设计语言》读书笔记-第二个字符串任意一个在第一个字符串出现的位置,未出先返回-1
2024-08-28 07:21:45
#include <stdio.h>
#include <string.h> #define Num 1000 int main()
{
int c,i,j = 0,m = 0,n = 0,k,count1 = 0,count2 = 0,w,h = 0,l = 0,flag2 = 0;
char s[Num],t[Num],str[Num] = {'\0'};
int number[Num],number2[Num],flag = 0; printf("Please input a string:\n"); while((c = getchar()) != EOF && c != '\n' && count1 < Num)
{
s[count1] = c;
count1++;
} printf("Please input another string:\n"); while((c = getchar()) != EOF && c != '\n' && count2 < Num)
{
t[count2] = c;
count2++;
} for(i = 0;i < count1;i++)
{
flag = 0; for(k = 0;k < m;k++)
{
if(s[i] == str[k])
{
flag = 1;
break;
}
} if(flag == 0)
{
for(j = 0;j < count2;j++)
{
if(s[i] == t[j])
{
str[m++] = s[i];
number[n++] = i;
number2[h++] = j;
break;
}
}
}
}
printf("The first location in str1 where any character from str2 occurs\n"); for(w = 0;w < count2;w++)
{
flag2 = 0; for(l = 0;l < m;l++)
{
if(w == number2[l])
{
printf("%c",str[l]);
printf(",%d\n",number[l]);
flag2 = 1;
break;
}
}
if(flag2 == 0)
printf("%c,-1\n",t[w]); } return 0;
}
费了好大劲,完成期间错误百出!要仔细点啊。
最新文章
- 冰球项目日志1-yjw
- sqlServer数据库插入数据后返回刚插入记录的自增ID
- 【CImg】霍夫变换——直线检测
- C#之数据分页
- soapUI 使用Property
- Ubuntu 14.04下java开发环境的搭建--3--Tomcat及MySQL的安装
- 【MySQL】使用 Optimizer Trace 观察SQL执行过程
- laravel5 事务回滚
- Codeforce E. Fire
- Winform退出运行后,删除运行目录(批处理方法)
- 【死磕 Spring】----- IOC 之 加载 Bean
- javascript高级程序设计第3版——第8章 BOM(浏览器对象模型)
- Thinkphp5多数据库切换
- Java使用HTTPClient4.3开发的公众平台消息模板的推送功能
- 将本地光盘做成yum源
- 基于jquery结婚电子请柬特效素材
- 让网站和APP更具动感的几点建议
- mysql 数据操作 单表查询 练习
- [BZOJ4311]向量(凸包+三分+线段树分治)
- JMeter常用元器件