加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

倒置英文句子中单词的字母顺序

发布时间:2020-12-13 22:15:07 所属栏目:百科 来源:网络整理
导读:1.倒置英文句子中单词的字母顺序 hello,I am good. - olleh,I ma doog. #includeiostream#includestring.husing namespace std;class Reverse{public: void Reverse_1(string s,string s2) { if(s.length()=0) return ; int i=0,j=0; while(s[i]!='') { wh

1.倒置英文句子中单词的字母顺序

hello,I am good. -> olleh,I ma doog.

#include<iostream>
#include<string.h>
using namespace std;

class Reverse
{
public:
    void Reverse_1(string s,string &s2)
    {
        if(s.length()<=0)
            return ;
        int i=0,j=0;
        while(s[i]!='')
        {
            while((s[i]>='a'&&s[i]<'z')||(s[i]>='A'&&s[i]<'Z'))
                i++;
            if(s[i]=='.'||s[i]=='!'||s[i]==','||s[i]=='?'||s[i]==' '||s[i]=='')
            {
                string temp=Reverse_2(s,j,i-1);
                s2+=temp;
                s2+=s[i];
                if(s[i]=='')
                    return;
            }
            i++;
            j=i;
        }
    }
    string Reverse_2(string s,int begin,int end)<span style="font-family: Arial;">//翻转每个单词.</span>
    {
        string s1;
        char temp;
        int index=begin,index1=end-begin+1;
        while(begin<=end)
        {
            temp=s[begin];
            s[begin]=s[end];
            s[end]=temp;
            end--;
            begin++;
        }
        return s.substr(index,index1);;
    }
};
int main()
{
    string str,s;
    s="";
    getline(cin,str);
    Reverse r;
    r.Reverse_1(str,s);
    cout<<s<<endl;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读