2026/6/9 18:30:42
网站建设
项目流程
广州市网站建设分站价格,网络营销个人感悟小结,什么是网络营销理论,平面设计线上兼职最长最短单词建立三个字符串#xff1b;一个表示当前判断的字符串in#xff0c;另两个表示要输出的最长long最短short单词。将输入的第一个单词赋值给最长最短单词#xff1b;后面用while#xff08;cin#xff09;循环以此判断#xff1a;将输入赋值给in#xff0c;然后…最长最短单词建立三个字符串一个表示当前判断的字符串in另两个表示要输出的最长long最短short单词。将输入的第一个单词赋值给最长最短单词后面用whilecin循环以此判断将输入赋值给in然后用“.length()函数”进行判断如果in大于long则将其赋值给long小于short则将其赋值给short。最后输出long和short。#includebits/stdc.husing namespace std;int main(){string shortword,longword;string in;cin in;shortword in;longword in;while(cin){cin in;if(in.length() longword.length()) longword in;if(in.length() shortword.length()) shortword in;}cout longword endl shortword endl;return 0;}单词翻转由于字符串开头和结尾可能有空格所以我用了getline获取输入定义两个字符串输入in和输出out然后遍历in的字符非空格则添加到out前面遇到空格则输出out并重置out。由于最后不一定遇到空格所以在循环外需要在输出一次out。尽管out可能为空格但不影响结果“out string(1,c) out”将字符添加到out前面也可以用“.insert(0,1,c)”函数表示在0位置插入1个字符c。#includebits/stdc.husing namespace std;int main(){string in;string out;getline(cin,in);for(char c : in){if(c ){cout out ;out ;}//cout out 保证单词之间的空格保证与原文一致else {out string(1,c) out;}}cout out endl;return 0;}判断字符串是否为回文这个比上一题简单一些只需存入字符串将反转后的字符串与原来字符串进行比较即可。#includebits/stdc.husing namespace std;int main(){string in,out;cin in;for(char c : in){out.insert(0,1,c);}//翻转后的字符串给outif(in out) cout yes endl;else cout no endl;return 0;}