strDivide2.cpp字符串划分

来源:互联网 发布:淘宝用户名可以更改吗 编辑:程序博客网 时间:2024/06/09 17:31
// strDivide2.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "string.h"/*s为 bwe@#$at111YYY*oo那么func(s)将打印atbweooYYY★树★(240028358)  21:07:57先挑字母,再排序吧国嵌唐老师(22134670)  21:21:25我来说说 怎么做1. 要先判断各个单词位置 把其它字符清成0, 这样字符数组中的就存放的是单词 组合 每个单词以0结束2. 申请一个字符指针数组  将每个元素指向不同的单词3. 写一个函数对这个指针数组排序  唐老师的微博地址是多少啊?http://weibo.com/u/1234587177*/bool isLowChar(char p){return (p>='a' && p<='z') ;}bool isUpChar(char p){return (p>='A' && p<='Z');}bool isChar(char p){return (p>='a' && p<='z') || (p>='A' && p<='Z');}void func(char *s){char* strArray[50];memset(strArray,0,sizeof(strArray));int strIndex=-1;char *p=s;bool isNewword=true;while(*p!='\0'){if(isChar(*p)){if(isNewword){strIndex++;strArray[strIndex]=p;isNewword=false;}}//if(isChar(*p))else{*p='\0';isNewword=true;}p++;}//while(*p!='\0')//排序for(int i=0;i<strIndex;i++){for(int j=i+1;j<=strIndex;j++)if((isLowChar(*strArray[i]) && isLowChar(*strArray[j])) || (isUpChar(*strArray[i]) && isUpChar(*strArray[j])) )if(*strArray[i] > *strArray[j]){char *ptmp=strArray[i];strArray[i]=strArray[j];strArray[j]=ptmp;}else if(isUpChar(*strArray[i])){char *ptmp=strArray[i];strArray[i]=strArray[j];strArray[j]=ptmp;}}//打印for( i=0;i<strIndex;i++){printf("%s\n",strArray[i]);}}int main(int argc, char* argv[]){char s[]="bwe@#$at111YYY*oo";func(s);return 0;}/*atbweYYYPress any key to continue*/