标签:type ace 空格 gets stdio.h 算法 str length button
1 #include<stdio.h> 2 #include<string.h> 3 #define max 100000 4 int is_zimu(char ch){//判断字符ch是否为字母:是返回1,否则返回0 5 if(ch>=‘a‘ && ch<=‘z‘ || ch>=‘A‘ && ch<=‘Z‘) 6 return 1; 7 else 8 return 0; 9 } 10 int main(){ 11 char str[max]; 12 int len=0,length=0; 13 int point,place; 14 gets(str); 15 int flag=1; 16 for(int i=0;i<=strlen(str);i++){ 17 if(!is_zimu(str[i])){//当前字符不是字母 18 if(len>length){ 19 length=len;//记录上一个单词长度 20 place=point; 21 } 22 flag=1;//标记置1 23 len=0;//单词长度清0,接下来记录下一个单词长度 24 }else{ 25 if(flag) 26 point=i;//存放当前字母元素的下标 27 len++;//单词长度+1 28 flag=0;//标记置0 29 } 30 } 31 for(int i=place;i<place+length;i++){ 32 printf("%c",str[i]); 33 } 34 return 0; 35 }
标签:type ace 空格 gets stdio.h 算法 str length button
原文地址:http://www.cnblogs.com/panweiwei/p/6623459.html