1035パスワード(20ポイント)
アイデア
面倒なchar配列を使用せずに、文字列型の検索と置換を使用して強制終了します。
文字列型は、文字列に要素があるかどうかを判断し、要素を置き換えるときに使用されます。
char型配列は、配列を変換するときにのみ使用され、その後に「\ 0」を付けることを忘れないでください
文字列型のreplace関数とfind関数の具体的な使用法を以下に示します。replaceには、使用する前に置換する記号が必要です。そうでない場合、エラーが報告されます。
int main() {
string a, b, c;
cin >> a >> b >> c;
int len=b.length();
while (a.find(b) != -1)
{
int i = a.find(b);
a.replace(i,len,c);
}
cout << a << endl;
return 0;
}
コード
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
string name[1005];
string strs[1005];
int num[1005]={
0};
int sum = 0;
for (int i =0 ;i<n;i++)
{
cin>> name[i]>>strs[i];
if (strs[i].find('1')!=-1 ||strs[i].find('l')!=-1||strs[i].find('0')!=-1||strs[i].find('O')!=-1)
{
sum+=1;
num[i]=1;
}
while (strs[i].find("1") != -1)
strs[i] = strs[i].replace(strs[i].find("1"),1, "@");
while (strs[i].find("l") != -1)
strs[i] = strs[i].replace(strs[i].find("l"),1, "L");
while (strs[i].find("0") != -1)
strs[i] = strs[i].replace(strs[i].find("0"),1, "%");
while (strs[i].find("O") != -1)
strs[i] = strs[i].replace(strs[i].find("O"),1, "o");
}
if(sum ==0)
if(n==1)
printf("There is %d account and no account is modified",n-sum);
else
printf("There are %d accounts and no account is modified",n-sum);
else
{
cout<<sum<<endl;
for (int i =0 ;i<n;i++)
if(num[i]!=0)
cout<<name[i]<<' '<<strs[i]<<endl;
}
}