2.20进制转化,表达式求值,删除字符

1.题目:

输入一个十进制数,将其化成N进制数输出(2≤N≤16)。 输出结果时,大于等于10的数字用字母代替,A代表10,B代表11以此类推。

输入:

100 10

100 15

输出:

100

6A
个人心得:

1.进制转化最主要的是将输入的数字与进制数相余,得到的数字存入数组当中,逆向输出此数组就得到转化后的数字

2.注意要输出某一数字时要将其-'0'

复制代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n, m;
	while (scanf("%d %d", &n, &m) != EOF) {
		vector<char>a;
		int remain;
		int reverse = n;
		if (n == 0) {
			printf("0\n");
			continue;
		}
		while (reverse!=0) {
			remain = reverse % m;
			if (remain < 10) {
				a.push_back('0' + remain);
			}
			else {
				a.push_back('A' + (remain - 10));
			}
			reverse = reverse / m;
		}
		for (int i = a.size() - 1; i >= 0; --i) {
			printf("%c", a[i]);
		}
		printf("\n");
	}
}

2.题目:

以字符串形式输入仅有整数和加减(正负)号构成的表达式,输出该表达式的值。

输入:

3+ 4+ 5+6

0+1

输出:

18

1

个人心得:

1.用getline读入字符串可以整行读入,不省略空格等字符

2.读入后对字符串遍历,如果遇到数字就进行转int处理,如果遇到运算符,就做相应运算

复制代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;

	while (getline(cin, s)) {
		int sum = 0;
		int num = 0;
		int sign = 1;

		for (int i = 0; i < s.size(); ++i) {
			if (s[i] >= '0' && s[i] <= '9') {
				num = num * 10 + (s[i] - '0');
			}
			else if (s[i] == '+') {
				sum = sum + sign * num;
				num = 0;
				sign = 1;
			}
			else if (s[i] == '-') {
				sum += sign * num;
				num = 0;
				sign = -1;
			}
			else {
				continue;
			}
		}
		sum += sign * num;
		printf("%d\n", sum);

	}
}

3.题目:

从键盘输入一个字符串和一个字符,将输入字符从字符串中删除,输出新的字符串。如果字符串中没有此字符,则原样输出字符串。

输入:

ab ccdc

c

输出:

ab d

个人心得:

1.同样用getline读入字符,用遍历,不同的就放入第三个字符串,最后输出就行

复制代码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
	string s;
	string a;
	string b;
	getline(cin,s);
	getline(cin,a);
	char temp = a[0];
	for (int i = 0; i < s.size(); ++i) {
		if (temp != s[i]) {
			b.push_back(s[i]);

		}
	}
	cout << b;
}

第一段:

Beyond these historical connections, there are strong ties between AI research and psychology, neurophysiology, and linguistics. Human-computer interface research also has connections with psychology. Roboticists work with both mechanical engineers and physiologists in designing new robots.

翻译:

除了这些历史联系之外,人工智能研究与心理学、神经生理学以及语言学之间也有着紧密的联系。人机交互研究同样与心理学相关。机器人学家在设计新型机器人时,会与机械工程师和生理学家合作。

第二段:

Computer science also has indirect relationships with virtually all disciplines that use computers. Applications developed in other fields often involve collaboration with computer scientists, who contribute their knowledge of algorithms, data structures, software engineering, and existing technology. In return, the computer scientists have the opportunity to observe novel applications of computers, from which they gain a deeper insight into their use. These relationships make computer science a highly interdisciplinary field of study.

翻译:

计算机科学还与几乎所有使用计算机的学科存在间接联系。其他领域开发的应用往往需要与计算机科学家合作,他们贡献自己在算法、数据结构、软件工程以及现有技术方面的知识。作为回报,计算机科学家有机会观察计算机的新型应用,从而对其使用获得更深入的理解。这些联系使计算机科学成为一门高度跨学科的研究领域。

第三段:

At one time, it was possible to define three distinct categories of computers. Mainframes were housed in large, closet-sized metal frames. Minicomputers were smaller, less expensive, and less powerful, but they could support multiple users and run business software. Microcomputers were clearly differentiated from computers in other categories because they were dedicated to a single user and their CPUs consisted of a single microprocessor chip.

翻译:

曾经,人们可以将计算机明确划分为三种不同的类别。大型机通常安置在大型、类似壁橱大小的金属机柜中。小型机体积更小、价格更低、性能也较弱,但它们可以支持多个用户并运行商业软件。微型计算机则与其他类别的计算机有明显区别,因为它们专门供单个用户使用,而且其中央处理器由单个微处理器芯片构成。

相关推荐
Dfreedom.5 小时前
分类算法的统一视角:从方差最大化到概率建模再到损失函数
算法·支持向量机·分类
汉克老师5 小时前
GESP2026年9月认证C++八级( 第三部分编程题(2、末班车))精讲
c++·gesp·小学生·学c++编程
Nebula_g5 小时前
JavaSE加强:Commons-io框架
java·开发语言·算法·javase
Do_It_Today5 小时前
php url路由入门实例
开发语言·php
小羊没烦恼!5 小时前
关于大型asp.net应用系统的架构-架构的选择
java·服务器·开发语言·前端·c#
夏幻灵6 小时前
前端八股:JavaScript 深拷贝详解:实现方式、递归原理与循环引用
开发语言·前端·javascript
梦帮科技6 小时前
【3.0修订版】音乐权利 NFT:MusicRightsNFT 的确权思想与授权关联
网络协议·算法·web3·区块链·密码学·智能合约·零知识证明
傲世仙尊6 小时前
C++起步-命名空间解决命名冲突与cin-cout缺省参数
开发语言·c++
hljqwb6 小时前
java服务异常日志只打印异常类型,没有堆栈定位分析(十)
java·开发语言
ym hyd 1116 小时前
生鲜超市库存管理信息系统源码 Java+SpringBoot+Vue3 前后分离
java·开发语言·vue.js·spring boot·毕设