Homework Introduction

ISBN

#include <bits/stdc++.h>
using namespace std;
string s;

int main() {
	cin >> s;
	int s1 = (s[0] - '0') * 1 + (s[2] - '0') * 2 + (s[3] - '0') * 3 + (s[4] - '0') * 4 + (s[6] - '0') * 5
	         + (s[7] - '0') * 6 + (s[8] - '0') * 7 + (s[9] - '0') * 8 + (s[10] - '0') * 9;
	s1 %= 11;
	if (s1 == 10 && s[12] == 'X') {
		cout << "Right";
	} else if (s1 == s[12] - '0') {
		cout << "Right";
	} else {
		for (int i = 0; i <= 11; i++) {
			cout << s[i];
		}
		if (s1 == 10) {
			cout << "X";
		} else {
			cout << s1;
		}
	}
	return 0;
}

相似字符串

// 操作方式:删除字符,插入字符,修改字符
// 其实删除和插入可以替换为一个,都替换为增加 b
#include <bits/stdc++.h>
using namespace std;
int t, la, lb;
string a, b;

int main() {
	cin >> t;
	while (t--) {
		cin >> a >> b;
		la = a.size();
		lb = b.size();
		if (la < lb) { // 保证 a是大的
			swap(a, b);
			swap(la, lb);
		}
		// 相差字符大于等于两个,不可能改成相等
		if (la - lb >= 2) {
			cout << "not similar" << endl;
			continue;
		}
		if (a == b) {
			cout << "similar" << endl;
			continue;
		}
		// 剩下的情况就是要么长度相等,要不长度不相等
		if (la == lb) { // 长度相等,统计不相等的字符个数
			int sum = 0 ;
			for (int i = 0; i < la; i++)
				if (a[i] != b[i])
					sum++;
			if (sum > 1)
				cout << "not similar" << endl;
			else
				cout << "similar" << endl;
			continue;
		} else { // 这里对应的就是长度不相等的情况,长度不相等,增加 b
			int ans = 0, f = 0;
			for (int i = 0; i < lb; i++) {
				if (a[i + ans] != b[i])
					ans = 1; // b需要在 i 位置增加一个字符
				if (ans && a[i + ans] != b[i]) { // 已经增加过了,还不相等,
					cout << "not similar" << endl;
					f = 1;
					break;  
				}
			}
			if (f == 0)
				cout << "similar" << endl;
		}
	}
	return 0;
}

小杨的字典

// 找到所有的单词,有翻译就翻译
// 没有翻译, UNK
// 一个单词是由两个标点符号隔开
// 标点符号原样输出
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
map<string, string > m;
int main() {
	cin >> n;
	while (n--) {
		string a, b;
		cin >> a >> b;
		m[a] = b; // 建立 a 和 b 的对应关系
	}
	cin >> s;
	s += '.'; //
	int len = s.size();
	string t = ""; // 用来存储单词
	string ans = "";
	// 找单词替换
	for (int i = 0; i < len; i++) {
		if (s[i] >= 'a' && s[i] <= 'z')
			t += s[i];
		else {  // 当前位置是一个标点符号
			if (t != "") {
				if (m.count(t))
					ans += m[t]; // 换成对应的翻译
				else
					ans += "UNK";
				t = "";
			}
			ans += s[i] ; // 当前字符也得加进来
		}
	}
	// 删除之前的 t
	ans.pop_back(); // 删除字符换的最后一个
	cout << ans;
	return 0;
}

Problem

Please claim the assignment to see the problems.
Status
Live...
Problem
12
Open Since
2025-8-6 0:00
Deadline
2025-8-31 23:59
Extension
24 hour(s)