第17周项目-15去除多余空格

来源:互联网 发布:株洲乐知在哪里 编辑:程序博客网 时间:2024/06/03 23:01
/** 程序的版权和版本声明部分* Copyright (c)2013, 烟台大学计算机学院学生* All rightsreserved.* 文件名称:main.cpp* 作    者:孔云* 完成日期:2013年12月20日* 版 本 号: v1.0* 输入描述:去除句子中多余空格。* 问题描述:深刻学习编程思路。*/#include<iostream>using namespace std;void aalltrim( char str[]);int main(){    char s[90]="qw eru   tru    io       hvjfh";    aalltrim(s);    cout<<"整理后的句子:"<<s;    return 0;}void aalltrim( char st[]){    bool nospace;    int i=0,j=0;    while(st[i]==' ')        i++;    nospace=true;    while(st[i]!='\0')    {        if(st[i]!=' ')        {            nospace=true;            st[j++]=st[i++];        }        else if(nospace)        {            nospace=false;            st[j++]=st[i++];        }        else        {            i++;        }    }    st[j]='\0';}


心得体会:看见这个程序,我头疼、、、、奋斗

0 0