Day30:2026年2月20日打卡

一、上机打卡

1.1 字符串排序

1.1.1 题目

输入一行字符串,全部由小写字母构成,对字符串按26个英文字母的先后顺序进行排序,然后输出。

输入样例

asdf

shflsahfslfdjsldfsjd

输出样例

adfs

adddffffhhjjlllsssss

1.1.2 总结

读取一行字符串,赋值给名为s的字符串,调用algorithm库里面的sort函数即可实现字符串排序。

cpp 复制代码
sort(s.begin(), s.end());

1.1.3 代码

cpp 复制代码
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string s;
	while (getline(cin, s)) {
		sort(s.begin(), s.end());
		cout << s << endl;
	}
	return 0;
}

1.2 回文问题

1.2.1 题目

输入一串字符,其长度小于200,判断该串字符是否构成回文。 所谓回文是指从左到右和从右到左读一串字符的值是一样的,如:ABCBA。

输入样例

abcba

abcbb

输出样例

Yes

No

1.2.2 总结

读入字符串为s,创建s的副本s1,使用algorithm库里面的reverse函数即可实现字符串逆置。

cpp 复制代码
reverse(s.begin(), s.end());

判断s1与s是否相等,若相等即为回文

1.2.3 代码

cpp 复制代码
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s;
	while (getline(cin, s)) {
		string s1 = s;
		reverse(s.begin(), s.end());
		if (s1 == s) cout << "Yes";
		else cout << "No";
		cout << endl;
	}
	return 0;
}

1.3 字符串中找整数

1.3.1 题目

对于一个字符串,编程找出其中的所有整数。例如,字符串"a12bc34d05",其中有整数12、34、5。

程序输入包括多行,每一行都是一串字符,字符串长度不超过500。字符串中的字符只有字母与数字。

程序输出为多行,每行第一个数代表所对应的字符串中整数的总个数。紧跟其后的依次是每个整数,数和数之间有一个空格。行与行之间没有多余空行,行首行尾没有多余空格。

输入样例

a12bc034d5

12886668&78711

abcdefghijklmn

输出样例

3 12 34 5

2 12886668 78711

0

1.3.2 总结

创建vector容器存取字符串s中出现的所有整数。

遍历s的每一个字符,若为数字,则读取该数字后的每一个数字,直到读取到数字即可。

创建num存储当前读到的数字,初始化为0,每读取到一位新的数字都令num = num * 10 + (s[i] - '0');

读取到非数字后,num存入容器中,并重新置为0。

1.3.3 代码

cpp 复制代码
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
using namespace std;
void solve(string s) {
	vector <int> data;
	for (int i = 0; i < s.size(); i++) {
		if (isdigit(s[i])) {
			int num = 0;
			while (i < s.size() && isdigit(s[i])) {
				//num = 10 * num + s[i++];
				num = 10 * num + (s[i++] - '0');
			}
			data.push_back(num);
			i--;
		}
	}
	cout << data.size();
	for (const int& val : data) 
		cout << " " << val;
	cout << endl;
}
int main() {
	string s;
	while (getline(cin, s)) {
		solve(s);
	}
	return 0;
}

二、翻译打卡

P1

原文:

To return, then, to the switching capabilities of a modern computer: computers in the1970s were generally able to handle eights witches at a time. That is, they could deal with eight binary digits, or bits, of data, at every cycle. A group of eight bits is called a byte, each byte containing 256 possible patterns of ONs and OFFs (or 1s and 0s).Each pattern is the equivalent of an instruction, a part of an instruction, or a particular type of datum, such as a number or a character or a graphics symbol. The pattern 11010010, for example, might be binary data---in this case, the decimal number 210---or it might be an instruction telling the computer to compare data stored in its switches to data stored in a certain memory-chip location.

译文:

那么,回到现代计算机的切换能力上:20 世纪70 年代的计算机通常每次可以处理 8 个开关。也就是说,它们可以在每个周期内处理 8 个二进制数字,即位。8 位一组称为字节,每个字节包含256 种可能的打开和关闭(或 1s 和 0s)模式。每个模式都相当于一条指令、指令的一部分或特定数据类型,例如数字、字符或图形符号。例如,模式11010010 可能是二进制数据------在这种情况下,十进制数 210------也可能是指令,告诉计算机将存储在开关中的数据与存储在特定存储器芯片位置中的数据进行比较。

P2

原文:

The development of processors that can handle 16, 32, and 64 bits of data at a time has increased the speed of computers. The complete collection of recognizable patterns---the total list of operations---of which a computer is capable is called its instruction set. Both factors---the number of bits that can be handled at one time, and the size of instruction sets---continue to increase withthe on going development of modern digital comp

译文:

能够同时处理 16、32 和 64 位数据的处理器的发展提高了计算机的速度。计算机能够识别的模式的完整集合------操作的总列表------称为其指令集。这两个因素------一次可以处理的数据位数和指令集的大小------随着现代数字计算机的不断发展而继续增加。

P3

原文:

Modern digital computers are all conceptually similar, regardless of size. Nevertheless, they can be divided into several categories on the basis of cost and performance: the personal computer or microcomputer, a relatively low-cost machine, usually of desktop size (though "laptops" are small enough to fit in a briefcase, and "palmtops" can fit into a pocket); the workstation, a micro computer with enhanced graphics and communications capabilities that make it especially useful for office work; the mini computer, generally too expensive for personal use, with capabilitiess uited to a business, school, or laboratory;and the main frame computer, a large,expensive machine with the capability of serving the needs of major business enterprises, government departments,scientific research establishments, or the like(the largest and fastest of these are called supercomputers).

译文:

现代数字计算机在概念上都是相似的,无论其大小。然而,它们可以根据成本和性能分为几类:个人计算机或微型计算机,这是一种成本相对较 低、通常为台式机大小的机器(尽管"膝上型"计算机小到可以放在公文包里,而"掌上型"计算机小到可以放在口袋里)​;工作站,这是一种具有增强的图形和通信功能的微型计算机,这使得它对办公室工作特别有用;小型计算机,通常对于个人使用来说过于昂贵,其功能适合于商业、学校或实验室;主机计算机,这是一种大型、昂贵的计算机,其功能可以满足大型企业、政府部门、科研机构等的需求(其中最大、最快的计算机被称为超级计算机)​。

三、单词打卡

相关推荐
blackicexs2 小时前
第五周第五天
算法
不吃橘子的橘猫2 小时前
《集成电路设计》复习资料2(设计基础与方法)
学习·算法·fpga开发·集成电路·仿真·半导体
halen3332 小时前
How Masters Tool Fixed My Digital Disaster
算法·均值算法·推荐算法
重生之后端学习2 小时前
78. 子集
java·数据结构·算法·职场和发展·深度优先
摸鱼仙人~3 小时前
0-1背包与完全背包:遍历顺序背后的秘密
人工智能·算法
juleskk3 小时前
2.15 复试训练
开发语言·c++·算法
那起舞的日子3 小时前
斐波那契数列
java·算法
wostcdk3 小时前
筛质数汇总
数据结构·算法
不吃橘子的橘猫3 小时前
《集成电路设计》复习资料4(Verilog HDL概述)
学习·算法·fpga开发·集成电路·仿真·半导体