B班第十七次课——字符串练习
2025-05-09 17:45:48
发布于:广东
A7846.【字符串】字典序
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(){
cin>>a>>b;
if(a>b) cout<<b<<" "<<a;
else if(a<b) cout<<a<<" "<<b;
else cout<<a;
return 0;
}
A398.子串判断
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main(){
cin>>s1>>s2;
if(s2.find(s1)!=string::npos){
cout<<s1<<" is substring of "<<s2;
}else if(s1.find(s2)!=string::npos){
cout<<s2<<" is substring of "<<s1;
}else{
cout<<"No substring";
}
return 0;
}
A7847.【字符串】字符串判等
// 忽略大小写:统一大小写-》ascii
#include<bits/stdc++.h>
using namespace std;
string s1,s2,s11="",s22="";
int main(){
getline(cin,s1);
getline(cin,s2);
//预处理:空格
for(int i=0;i<s1.length();i++){
if(s1[i]!=' ') s11+=s1[i];
}
//处理:大小写
for(int i=0;i<s11.length();i++){
if(s11[i]>='a' && s11[i]<='z'){
s11[i]-=32;
}
}
for(int i=0;i<s2.length();i++){
if(s2[i]!=' ') s22+=s2[i];
}
//处理:大小写
for(int i=0;i<s22.length();i++){
if(s22[i]>='a' && s22[i]<='z'){
s22[i]-=32;
}
}
if(s11==s22) cout<<"YES";
else cout<<"NO";
return 0;
}
A401.简单密码
#include<bits/stdc++.h>
using namespace std;
string s1;
int main(){
getline(cin,s1);
for(int i=0;i<s1.size();i++){
if(s1[i]>='F' && s1[i]<='Z'){
s1[i]-=5;
}else if(s1[i]>='A' && s1[i]<='E'){
s1[i]+=21;
}
}
cout<<s1;
return 0;
}
回放链接:https://share.weiyun.com/zcsdCsX7 密码:3hh8q8
这里空空如也
有帮助,赞一个