CSP-JS 复赛复习 习题记录——字符串(东方博宜OJ)

家人们,这不要考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:10
	ll 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. 字符串对比


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值