家人们,这不要考CSP复赛了嘛,就做了几个复习题单,和大家分享分享,也就随便做做, 望大家多多关照!
网址:东方博宜OJ - 字符串 题单
食用说明:这次的题 太简单了 还不算太难,就不放说明了,直接上代码!(鼓掌)
1093. 打印小写字母表
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);for (char c = 'a'; c <= 'm'; c++) {cout << c;}cout << endl;for (char c = 'n'; c <= 'z'; c++) {cout << c;}cout << endl;for (char c = 'z'; c >= 'n'; c--) {cout << c;}cout << endl;for (char c = 'm'; c >= 'a'; c--) {cout << c;}cout << endl;return 0;
}
1101. 时间的差
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
typedef long long ll;
using namespace std;static ll num(string s) {ll r = 0;//01:10:10ll h = (s[0] - '0') * 10 + (s[1] - '0');ll m = (s[3] - '0') * 10 + (s[4] - '0');ll e = (s[6] - '0') * 10 + (s[7] - '0');r = h * 60 * 60 + m * 60 + e;return r;
}int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);string s1, s2;cin >> s1 >> s2;cout << num(s1) - num(s2) << endl;return 0;
}
1115. 数字和
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);string s;getline(cin, s);ll l = s.size(), sum = 0;for (ll i = 0; i < l; i++) {sum += s[i] - '0';}cout << sum << endl;return 0;
}
1134. 国王的魔镜
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;bool palin(string s, int end)
{bool f;if ((end + 1) % 2 == 0){f = true;for (int i = 0; i <= end / 2; i++){if (s[i] != s[end - i]){f = false;break;}}}else{return false;}return f;
}int main() {ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);string s;cin >> s;ll end = s.size() - 1;while (palin(s, end)) {end /= 2;}cout << end + 1 << endl;return 0;
}
1387. 简单加密
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);string s;getline(cin, s);ll len = s.size();for (ll i = 0; i < len; i++) {if (isupper(s[i])) {if (s[i] >= 'F' && s[i] <= 'Z') {s[i] -= 5;}else {s[i] = s[i] + ('V' - 'A');}}}cout << s << endl;return 0;
}
1480. 找字典码最小的字符串
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);ll n;cin >> n;string mins, s;cin >> mins;for (ll i = 2; i <= n; i++) {cin >> s;if (s < mins) mins = s;}cout << mins << endl;return 0;
}
1475. 字符串对比