SpringBoot整合SpringDataJPA依賴和配置匯入
阿新 • • 發佈:2021-01-27
Description
編寫一個程式實現將字串中的所有”you”替換成”we”
Input
輸入包含多行資料
每行資料是一個字串,長度不超過1000
資料以EOF結束
Output
對於輸入的每一行,輸出替換後的字串
Sample Input
you are what you do
Sample Output
we are what we do
①利用string函式
#include<bits/stdc++.h>
using namespace std;
int main()
{
string str;
while(getline(cin,str))
{
int start=str. find("you");
while(start!=string::npos)//保證不是字串尾
{
str.replace(start,3,"we");
start=str.find("you",start+2);
}
cout<<str<<endl;
}
return 0;
}
②不利用string函式
#include<bits/stdc++.h>
using namespace std;
int main()
{
int i=0,j;
char a[1001];
while (scanf("%s",a)!=EOF)
{
if(strcmp(a,"you")==0)
strcpy(a,"we");
cout<<a<<' ';
}
return 0;
}