牛客网一站通Offer考试第一题

来源:互联网 发布:萨伏伊别墅尺寸数据 编辑:程序博客网 时间:2024/05/29 12:18

这里写图片描述

#include <iostream>#include <string>using namespace std;int main(){    string str="This is a sample";    int begin,end;    int j=0;    for(int i=0;i<16;i++)    {        if(str[i]>=65&&str[i]<=90&&str[i]!=' '){            str[i]+=32;            continue;        }        if(str[i]>=97&&str[i]<=122&&str[i]!=' ')            str[i]-=32;    }       reverse(str.begin(),str.end());    while(str[j])    {        if(str[j]!=' ')        {            begin=j;            while(str[j]!=' '&&str[j])                j++;            j=j-1;            end=j;        }        while(end>begin)        {            char temp;            temp=str[begin];            str[begin]=str[end];            str[end]=temp;            begin++;            end--;        }        j++;    }    cout<<str<<endl;    return 0;}
0 0