7.17
1.7题目训练
02
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[30];
int main()
{
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i ++ )
{
a[s[i] - 'a'] ++;
}
for (int i = 0; i < n; i ++ )
{
if (a[s[i] - 'a'] == 1)
{
cout << s[i] << endl;
return 0;
}
}
cout << "no" << endl;
return 0;
}
09
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int a[30];
int main()
{
string s;
getline(cin,s);
int n = s.size();
for (int i = 0; i < n; i ++ )
{
if ((s[i] >= 'a' && s[i] <= 'y') || (s[i] >= 'A' && s[i] <= 'Y')) s[i] = s[i] + 1;
else if(s[i] == 'z' || s[i] == 'Z') s[i] = s[i] - 25;
cout << s[i];
}
return 0;
}
注;10与9类似
011
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char p[210], pp[210];
int main()
{
for (int i = 0; i <= 100; i ++ ) p[i] = '0', pp[i] = '0';
string a, b, q;
cin >> a >> b >> q;
bool flag = true;
for (int i = 0; i < a.size(); i ++ )
{
int hh = a[i] - 'A';
if (p[hh] != '0' && p[hh] != b[i]) flag = false;
p[hh] = b[i];
pp[b[i] - 'A'] = a[i];
}
for (int i = 0; i < 26; i ++ ) if (p[i] == '0' || pp[i] == '0') flag = false;
if (flag == false) cout << "Failed" << endl;
else
{
for (int i = 0; i < q.size(); i ++ ) cout << p[q[i] - 'A'];
}
return 0;
}
012
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char p[210], pp[210];
int main()
{
string s;
getline(cin, s);
int n = s.size();
for (int i = 0; i < n; i ++ )
{
if (s[i] >= 'x' && s[i] <= 'z') s[i] = 'a' + (s[i] - 'x');
else if (s[i] >= 'X' && s[i] <= 'Z') s[i] = 'A' + (s[i] - 'X');
else s[i] += 3;
if (s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
else s[i] = s[i] - 'a' + 'A';
}
for (int i = n - 1; i >= 0; i -- )
{
cout << s[i];
}
return 0;
}
019
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char p[210], pp[210];
int main()
{
string a, b;
cin >> a >> b;
if (a.size() < b.size()) swap(a, b);
a += a;
int n = a.size();
int m = b.size();
int i = 0, j = 0;
while (i < n && j < m)
{
if (a[i] != b[j]) i ++ , j = 0;
else i ++, j ++ ;
}
if (j == m) cout << "true" << endl;
else cout << "false" << endl;
return 0;
}
033
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
string s;
cin >> s;
int len = s.size();
for (int i = 0; i < len / 2; i ++ )
{
if (s[i] != s[len - i - 1])
{
cout << "no" << endl;
return 0;
}
}
cout << "yes" << endl;
return 0;
}
034
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
string s;
int check(int x, int y)
{
int a = x, b = y;
while (a <= b)
{
if (s[a] != s[b]) return 0;
a ++ , b -- ;
}
for (int i = x; i <= y; i ++ ) cout << s[i];
cout << endl;
return 0;
}
int main()
{
cin >> s;
int len = s.size();
for (int k = 1; k < len; k ++ )
for (int i = 0; i <= len - k; i ++ )
check(i, i + k);
return 0;
}