NOIP2011统计单词数
2015-07-24 22:24
323 查看
分析:常规题,一次扫描即可,但要注意大小写和没出先要输出-1.判断是否是某个单词的一部分可以通过判断后一个词是不是空格或\0来解决。上题。
#include <stdio.h> #include<string.h> #define MAX 1000 int main() { char str[MAX]; char word[MAX]; int i,lenth,j=0; int t,L; int num=0,pos; gets(word); gets(str); lenth=strlen(str); L=strlen(word); for(i=0;i<lenth;i++) { if(str[i]==word[j]||(str[i]+32)==word[j]||(str[i]-32)==word[j]) //大小写一样也可以 { j++; if(j==1) t=i; //标记第一次的位置 } else { j=0; //不是该单词清零 } if(j==L&&(str[i+1]==' '||str[i+1]=='\0')) //判断是不是某词的一部分 { if(num==0) pos=t; num++; } } if(num==0) printf("-1"); else printf("%d\n%d",num,pos); return 0; }
相关文章推荐
- jQuery 2.x 不支持IE9以下的IE浏览器
- To find the kth to Last Element of a Singly Linked List
- 事件冒泡和事件捕获
- ch8 对象的容纳
- 机器学习-组合算法总结
- ch6 类再生
- Openssl pkcs7命令
- 关于将navigationBar的背景设置成透明,并且让navigationItem展示出来
- 股票学习(技术指标)
- 大数运算问题
- hdu 1323 Perfection
- ch5 隐藏实施过程
- ch3 控制程序流程
- Leetcode 5 Longest Palindromic Substring
- poj3468 A Simple Problem with Integers
- 素数距离问题
- hihoCoder - 1079 - 离散化 (线段树 + 离散化)
- OpenCV图像处理篇之腐蚀与膨胀
- 多线程编程模型
- ch4 初始化和清除