将字符串中的单词倒置
发布时间:2020-12-13 22:46:06 所属栏目:百科 来源:网络整理
导读:例如: 输入:i came from china. 输出:china. from came i while (ji){temp=str[j];str[j]=str[i];str[i]=temp;j--;i++;}coutstrendl;//字符串逆转了i=0;while(str[i]!=' '){if(str[i]!=' '){begin=i;//begin 是第一个单词开始的地方while (str[i]str[i]!
例如: 输入:i came from china. 输出:china. from came i while (j>i) { temp=str[j]; str[j]=str[i]; str[i]=temp; j--; i++; } cout<<str<<endl;//字符串逆转了 i=0; while(str[i]!=' ') { if(str[i]!=' ') { begin=i;//begin 是第一个单词开始的地方 while (str[i]&&str[i]!=' ') i++; i--; end=i;//end是第一个单词结束的地方 } while(end>begin) { temp=str[begin]; str[begin]=str[end]; str[end]=temp; end--; begin++; } i++; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |