提取字符串,并对字符串按字典序排序

  问题:
  从标准输入读入任意多个字符串,字符串用#分割。最后输入一个固定的标识输入结束的字符串,如";\*.",对输入的所有字符串按字典序排序,并输出到一个文件中。同时统计出字符串个数、最长字符串、最短字符串。
  测试字符串如: qwer#uoy iiu89;#yuiji799#yuiojs;pp#dgfdb#abc;\*.
  ==============================================
  #include
  #include
  #include
  const int N = 1000;
  using namespace std;
  struct struct_str
  {
  char* ch;
  int length;
  };
  int strDeal(char* str,std::vector& strvector)
  {
  int n = 0;
  int count = 0; //统计字符串的个数
  //先找到结束的位置
  while(str[n] != '\0')
  {
  if((str[n]==';') && (str[n+1]=='\\') && (str[n+2]=='*') && (str[n+3]=='.'))
  break;
  n++;
  }
  int i,j; //i指向首,j指向尾
  if(str[0]!='#') //首字符不是'#'
  i = j = 0;
  else //首字符是'#'
  i = j = 1;
  int p=0;
  p++;
  while(j& strvector)
  {
  int countN = strvector.size();
  int *a = new int[countN];
  for(int i=0;i::iterator iter;
  int i,k,j,t;
  //选择排序
  for(i=0;istrvector[maxB].length)
  maxB = i;
  }
  cout字符串进行排序后的结果见文件'result.txt'!" strVector;
  char *str = new char[N];
  cout>str; //遇到空格就会终止读入
  gets_s(str,N); //或者用gets(str);
  int count = strDeal(str,strVector);
  std::vector::iterator iter;
  for(iter=strVector.begin();iter!=strVector.end();+ +iter)
  coutch字符串!"<<endl;
  }
  ====================
  运行结果:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值