hdu4847:Wow! Such Doge!(字符串匹配)
2024-09-03 09:58:10
题目大意:在给出的段落里面找出“doge”出现的次数。大写和小写都能够。
解题思路:字符串匹配问题,能够在之前将字母都转换成统一格式。
代码:
#include <stdio.h>
#include <string.h> const int N = 1e6;
char str[N];
const char *s1 = "doge"; int find () { int sum = 0;
char *p = strstr(str, s1);
while (p != NULL) { sum++;
p = p + 4;
//if (*p == '\0')
// break; p = strstr (p, s1);
}
return sum;
} int main () { int count = 0;
while (scanf ("%s", str) != EOF) { for (int i = 0; i < strlen (str); i++)
if (str[i] >= 'A' && str[i] <= 'Z')
str[i] += 32;
count += find ();
}
printf ("%d\n", count);
return 0;
}
最新文章
- less简单用法
- 三层架构与MVC &;amp; 设计模式的较量
- 50行代码仿backbone_todos
- Mac运行exe的几种方法,欢迎补充!
- namespace的用法
- VBA在WORD中给表格外的字体设置为标题
- Android之动态图片
- Android程序安装后在模拟器上不显示,并且控制台显示The launch will only sync the application package on the device!
- 在vim保存时获得sudo权限
- Swift语言指南(八)--语言基础之元组
- linux权限解读
- HDU1212
- Akka(42): Http:身份验证 - authentication, autorization and use of raw headers
- CentOS6.8 安装node.js npm
- python机器可读数据-json
- 【2018.05.11 智能驾驶/汽车电子】非技术向:关于Simulink和AutoSar的几种观点
- 四、触发器(Trigger)
- Mysql 中获取刚插入的自增长id的值
- Asp连接Oracle (包含绿色版12.2客户端和ODBC驱动安装)
- oracle 配置本地Net服务