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.

翻译:

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

相关推荐
KANGBboy7 分钟前
java知识五(继承)
java·开发语言
c++之路9 分钟前
Bazel C++ 构建系列文档(三):构建第一个 C++ 项目
开发语言·c++
AI人工智能+电脑小能手11 分钟前
【大白话说Java面试题 第117题】【并发篇】第17题:线程有几种状态,之间如何转换?
java·开发语言·面试
开源Z14 分钟前
LeetCode 42 · 接雨水:从暴力到双指针的三步优化
算法·leetcode
旖-旎24 分钟前
《LeetCode 695 岛屿的最大面积 FloodFill DFS 解法》
c++·算法·力扣·深度优先遍历·floodfill
森G42 分钟前
61、信号与槽机制在 TCP 编程中的应用---------网络编程
网络·c++·qt·网络协议·tcp/ip
syagain_zsx1 小时前
STL 之 vector 讲练结合
c++·算法
聚名网1 小时前
域名net,com,cn有区别吗?有哪些不同呢?
服务器·开发语言·php
牛油果子哥q1 小时前
STL set与map底层精讲,红黑树适配原理、有序去重特性、迭代器遍历、API实战与面试核心考点全解
开发语言·数据结构·c++·面试
foundbug9991 小时前
直流电机 PID 速度控制 MATLAB 仿真程序
开发语言·matlab