64,636
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
cout<<"Input a sentence: (press ctrl+z to end)" << endl;
string str;
while(getline(cin, str))
{
for(string::size_type index = 0; index != str.size(); ++index)
{
if(islower(str[index]))
{
str[index] = toupper(str[index]);
}
else if(isupper(str[index]))
{
str[index] = tolower(str[index]);
}
}
cout << str << endl;
}
cin.clear();
return 0;
}
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string convert(const string &line)
{
string findBullShit=line,copyLine=line;
for(string::size_type i=0;i!=findBullShit.length();++i)
{
if( 'a'<=findBullShit[i] && findBullShit[i]<='z' || 'A'<=findBullShit[i] && findBullShit[i]<='Z')
{
findBullShit[i]|=32; //全部转化成小写
}
}
string::size_type pos=0;
while( ( pos=findBullShit.find("bullshit",pos) ) != string::npos ) //替换不良词汇
{
//findBullShit.replace(pos,strlen("bullshit"),"bush");
copyLine.replace(pos,strlen("bullshit"),"BUSH");
++pos;
}
for(string::size_type i=0;i!=copyLine.size();++i) //逆转大小写
{
if('a'<=copyLine[i] && copyLine[i]<='z')
{
copyLine[i]&=~32;
}
else if('A'<=copyLine[i] && copyLine[i]<='Z')
{
copyLine[i]|=32;
}
}
//pos=0;
/*
while( ( pos=copyLine.find("BUSH",pos) ) != string::npos ) //逆转"BUSH"到"bush"
{
copyLine.replace(pos,strlen("BUSH"),"bush");
}
*/
string::size_type i,j;
for(i=-1,j=0;j!=copyLine.size();++j) //去除多余空格
{
if(i!=-1 && copyLine[i]==' ' && copyLine[j]==' ')
{
continue;
}
copyLine[++i]=copyLine[j];
}
return copyLine.substr(0,i+1); //返回结果
}
int main()
{
string input;
getline(cin,input);
cout<<convert(input)<<endl;
return 0;
}
while( ( pos=findBullShit.find("bullshit",pos) ) != string::npos ) //替换不良词汇
{
//findBullShit.replace(pos,strlen("bullshit"),"bush");
copyLine.replace(pos,strlen("bullshit"),"bush");
}
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
string convert(const string &line)
{
string findBullShit=line,copyLine=line;
for(string::size_type i=0;i!=findBullShit.length();++i)
{
if( 'a'<=findBullShit[i] && findBullShit[i]<='z' || 'A'<=findBullShit[i] && findBullShit[i]<='Z')
{
findBullShit[i]|=32; //全部转化成小写
}
}
string::size_type pos=0;
while( ( pos=findBullShit.find("bullshit",pos) ) != string::npos ) //替换不良词汇
{
findBullShit.replace(pos,strlen("bullshit"),"bush");
copyLine.replace(pos,strlen("bullshit"),"bush");
}
for(string::size_type i=0;i!=copyLine.size();++i) //逆转大小写
{
if('a'<=copyLine[i] && copyLine[i]<='z')
{
copyLine[i]&=~32;
}
else if('A'<=copyLine[i] && copyLine[i]<='Z')
{
copyLine[i]|=32;
}
}
pos=0;
while( ( pos=copyLine.find("BUSH",pos) ) != string::npos ) //逆转"BUSH"到"bush"
{
copyLine.replace(pos,strlen("BUSH"),"bush");
}
string::size_type i,j;
for(i=-1,j=0;j!=copyLine.size();++j) //去除多余空格
{
if(i!=-1 && copyLine[i]==' ' && copyLine[j]==' ')
{
continue;
}
copyLine[++i]=copyLine[j];
}
return copyLine.substr(0,i+1); //返回结果
}
int main()
{
string input;
getline(cin,input);
cout<<convert(input)<<endl;
return 0;
}
buLLShIt , heLLo 123 !!~ buul, bull shit,shitBuLLLl,bullshit,bB
bush , HEllO 123 !!~ BUUL, BULL SHIT,SHITbUlllL,bush,Bb
#include <stdio.h>
int main(){
char str[1000];
int i;
while(gets(str)){
for(i = 0; str[i]; i++){
if(str[i] >= 'a' && str[i] <= 'z')
printf("%c",str[i] - 32);
else if(str[i] >= 'A' && str[i] <= 'Z')
printf("%c",str[i] + 32);
else
putchar(str[i]);
}
putchar(10);
}
return 0;
}
string str1, str2("bullshit");
getline(cin, str1);// 可以输入空白符
string::size_type pos = str1.find(str2, 0);// 返回bullshit在str1中的下标pos
str1.replace(pos, strlen("bullshit"), "bush");// 将bullshit替换为bush,并返回str1的引用
#include<string>
#include<iostream>
using namespace std;
void main()
{
string s;
cout<<"Input s:\n";
cin>>s;
size_t i;
for(i=0; i<s.length() ;i++)
{
if(s[i]>='a' && s[i]<='z')
{
s[i]=s[i]^32;
}
else
{
s[i]=s[i]|32;
}
}
cout<<s;
}
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
for(int i = 0;i < str.length(); ++i )
{
if(str[i] >= 'a' && str[i] <= 'z' )
{
str[i] = str[i] - 32;
}
else if( str[i] >= 'A' && str[i] <= 'Z' )
{
str[i] = str[i] + 32;
}
}
cout << str << endl;
}
return 0;
}