基础82:输入一个十进制数,将其化成N进制数输出(2≤N≤16)。 输出结果时,大于等于10的数字用字母代替,A代表10,B代表11以此类推。
cpp
#include <stdio.h>
#include <stdlib.h>
int main(){
int num, type;
while( scanf("%d %d",&num,&type) != EOF){
if(type == 10){
printf("%d\n",num);
continue;
}
if(num==0){
printf("0\n");
continue;
}
int ans[20]={0};
int index = 0;
char digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
while (num > 0) {
ans[index++] = num % type;
num /= type;
}
for (int i = index - 1; i >= 0; i--) {
printf("%c", digits[ans[i]]);
}
printf("\n");
}
}
基础83:以字符串形式输入仅有整数和加减(正负)号构成的表达式,输出该表达式的值。
cpp
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
char line[100];
while (fgets(line, sizeof(line), stdin) != NULL) {
int ans=0;
int YunSuanFu=-1;//0表示-,1表示+
int num=0;
int YunSuan=0; //当检测到第二个运算符时进行前一个运算
for(int i=0;i<100;i++){
if(line[i] == '\0'|| line[i] == '\n'){
//结束运算,对记录的最后一个运算符进行计算
if(YunSuan==1){
//检测到第二个运算符时进行运算
if(YunSuanFu==1)ans+=num;
else ans-=num;
YunSuan--;
}
break;
}
char ZiFu=line[i];
if(ZiFu == ' '){//空格直接跳到 下一个循环
continue;
}
if(ZiFu == '-'){
YunSuan++;
if(YunSuan==2){
//检测到第二个运算符时进行运算
if(YunSuanFu==1)ans+=num;
else ans-=num;
YunSuan--;
}
YunSuanFu=0;
num=0;//遇到运算符,开始记录下一个数
continue;
}
if(ZiFu == '+'){
YunSuan++;
if(YunSuan==2){
//检测到第二个运算符时进行运算
if(YunSuanFu==1)ans+=num;
else ans-=num;
YunSuan--;
}
YunSuanFu=1;
num=0;//遇到运算符,开始记录下一个数
continue;
}
//以上都不是时,当前字符为数字
num = num*10+line[i] - '0' ;
if(YunSuan==0){
//第一个数字,存起来
ans = num;
}
}
printf("%d\n", ans);
}
return 0;
}
基础84:从键盘输入一个字符串和一个字符,将输入字符从字符串中删除,输出新的字符串。如果字符串中没有此字符,则原样输出字符串。
cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
char data[20];
char deleteChar;
fgets(data, sizeof(data), stdin);
int c;
while ((c = getchar()) == '\n'); // 只跳过换行符
deleteChar = c; // c 可以是空格、字母、数字等任何字符
for(int i=0;i<20;i++){
if(data[i] != deleteChar)printf("%c",data[i]);
if(data[i]=='\0' || data[i]=='\n')break;
}
}
个人总结:
- 接收一行字符串:fgets(line, sizeof(line), stdin)=fgets(字符数组, 最大读取长度, 文件流)
- scanf("%s", line) 读取字符串时,遇到空格就会停止
- scanf(" %c",&c) 占位符前加一个空格,表示接收一个非回车、空格的字符
- 需要接收一个非特定字符的字符:int c; while ((c = getchar()) == '\n'); deleteChar = c;
- c为int是因为字符本身储存依然是整数的ASCII码
Analogue computers began to be built in the late 19th century. Early models calculated by means of rotating shafts and gears. Numerical approximations of equations too difficult to solve in any other way were evaluated with such machines. Lord Kelvin built a mechanical tide predictor that was a specialized analogue computer. During World Wars I and II, mechanical and, later, electrical analogue computing systems were used as torpedo course predictors in submarines and as bombsight controllers in aircraft. Another system was designed to predict spring floods in the Mississippi River basin.
- shaft 轴,approximation 近似值,specialized 专业的,torpedo 鱼雷,torpedo course 鱼雷航路,bombsight 轰炸瞄准器,spring floods 春季洪水,basin 盆地/流域
- 模拟计算机起始于19世纪末被造出。早期型号 的算术以旋转轴和齿轮来实现。这样的机器以其他的形式来计算等式的数字近似值被评估为是很困难的那些用其他方法难以求解的方程,其数值近似值就是用这种机器计算出来的 。开尔文勋爵造出了机械潮流的先驱机械潮汐预测器 ,即专业的模拟计算机。在一战和二战期间及其之后,机械的以及后来的 电子的模拟计算系统曾被用来作为鱼雷航路预测在潜水艇中和飞机的轰炸瞄准器控制器。在密西西比河流域,其他的系统曾被设计来预测春季洪水。
During World War II, a team of scientists and mathematicians, working at Bletchley Park, north of London, created one of the first all-electronic digital computers: Colossus. By December 1943, Colossus, which incorporated 1,500 vacuum tubes, was operational. It was used by the team headed by Alan Turing", in the largely successful attempt to crack German radio messages enciphered in the Enigma code.
- operational 可用的/业务上的/运营的
- 在二战中,一个由科学家和数学学家组成的团队在伦敦的布莱切利庄园研究并创造出了首批 第一台全电子数字计算机之一 :巨像。在1943年的十二月,装入了1500个真空管的巨像运转了。由艾伦图灵引领的团队使用这台设备进行了巨大成功的尝试,将德国无线电信息破译成恩尼格码破解以恩尼格码加密的德国无线电信息。
Independently of this, in the United States, a prototype electronic machine had been built as early as 1939, by John Atanasoff and Clifford Berry2 at Iowa State College³. This prototype and later research were completed quietly and later overshadowed by the development of the Electronic Numerical Integrator And Computer (ENIAC) in 1945. ENIAC was granted a patent, which was overturned decades later, in 1973, when the machine was revealed to have incorporated principles first used in the Atanasoff-Berry Computer.
- Independently of this 与此无关,incorporated principles 纳入原则
- 在美国,与此独立地, 由约翰·阿塔纳索和克利福德·贝里在艾奥瓦州立学院一样早地在1939年造出一个与巨像计算机无关的电子机械原型机。这台原型机和之后的研究都悄悄完成,后来,很快在1945年电子数字积分计算机的构建使其相形见绌。在1973年,电子数字积分计算机获得了专利,后来很快就在几十年后的1973年被推翻,该设备被爆出纳入原则最先使用在阿塔纳索夫-贝瑞计算机。