Day31:代码打卡题(85-87) + 英语翻译 + 单词打卡
没有加endl,控制台输出缓冲不会立即刷新,即使cnt有值,也可能看不到输出(尤其是cnt=0时)。2.代码中while(getline(cin, s))会一直等待输入直到接收到 “文件结束符”,而手动在控制台输入完所有行后,程序无法判断输入是否结束,因此会卡在循环中,必须按Ctrl+Z(Windows)/Ctrl+D(Linux)发送结束符,程序才能退出循环并输出结果。代码int main()s
题目85:手机短号
问题描述
大家都知道,手机号是一个11位长的数字串,同时,作为学生,还可以申请加入校园网,如果加入成功,你将另外拥有一个短号。假设所有的短号都是“6”+手机号的后5位,比如号码为13512345678的手机,对应的短号就是645678。
现在,如果给你一个11位长的手机号码,你能找出对应的短号吗?
输入说明
输入数据的第一行是一个N(N <= 1000),表示有N个数据,接下来的N行每一行为一个11位的手机号码。
输出说明
输出应包括N行,每行包括一个对应的短号,输出应与输入的顺序一致。
输入范例
2
70711457490
47810534444
输出范例
657490
634444
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
cin >> n;
while(n --)
{
string s;
cin >> s;
cout << '6';
for(int i = 6; i < s.size(); i ++)
{
cout << s[i];
}
cout << endl;
}
return 0;
}
题目86:字符串统计
问题描述
对于给定的一个字符串,统计其中小写字母出现的次数。
输入说明
输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。
输出说明
对于每个测试实例,输出该串中数值的个数,每个输出占一行。
输入范例
2
abadvbsbasdfWRWEFASDFASDFwefsadfasdfadef934577&%^&*(
adfasdferdasd233dsf234radfassdfasdf**HHIKKK
输出范例
27
29
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
cin >> n;
while(n --)
{
string s;
int cnt = 0;
cin >> s;
for(int i = 0; i < s.size(); i ++)
{
if(s[i] >= 'a' && s[i] <= 'z') cnt ++;
}
cout << cnt << endl;
}
return 0;
}
题目87:弟弟的作业
问题描述
你的弟弟刚做完了“100以内数的加减法”这部分的作业,请你帮他检查一下。每道题目(包括弟弟的答案)的格式为a+b=c或者a-b=c,其中a和b是作业中给出的,均为不超过100的非负整数;c是弟弟算出的答案,可能是不超过200的非负整数,也可能是单个字符"?",表示他不会算。
输入说明
输入文件包含不超过100行,以文件结束符结尾。每行包含一道题目,格式保证符合上述规定,且不包含任何空白字符。输入的所有整数均不含前导0。
输出说明
输出仅一行,包含一个非负整数,即弟弟答对的题目数量。
输入范例
55+12=67
15-8=7
100-35=?
83-50=33
4-3=6
81+5=21
输出范例
3
个人总结
1.cout << cnt; 没有加endl,控制台输出缓冲不会立即刷新,即使cnt有值,也可能看不到输出(尤 其是cnt=0时)。
2.代码中while(getline(cin, s))会一直等待输入直到接收到 “文件结束符”,
而手动在控制台输入完所有行后,程序无法判断输入是否结束,因此会卡在循环中,
必须按Ctrl+Z(Windows)/Ctrl+D(Linux)发送结束符,程序才能退出循环并输出结果。
代码
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
string s;
int cnt = 0;
while(getline(cin , s))
{
int sum = 0;
int size = 1;
for(int i = 0; i < s.size(); i ++)
{
if(s[i] >= '0' && s[i] <= '9')
{
int num = 0;
int j;
for(j = i; s[j] >= '0' && s[j] <= '9' && j < s.size(); j ++)
{
num *= 10;
num += s[j] - '0';
}
sum += size * num;
i = j - 1;
}
else if(s[i] == '+') size = 1;
else if(s[i] == '-') size = -1;
else if(s[i] == '=')
{
int target = 0;
if(s[i + 1] >= '0' && s[i + 1] <= '9')
{
for(int j = i + 1; s[j] >= '0' && s[j] <= '9' && j < s.size(); j ++)
{
target *= 10;
target += s[j] - '0';
}
}
else if(s[i + 1] == '?') break;
if(target == sum) cnt ++;
break;
}
}
}
cout << cnt << endl;
return 0;
}
英语翻译
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 with the ongoing development of modern digital computers.
能够一次处理 16 位、32 位和 64 位数据的处理器的发展,提升了计算机的运行速度。完整的可识别模式集合——操作的完整清单——计算机所能够执行的操作被称为指令集。这两个因素——一次能够处理的位数,以及指令集的规模——都随着现代数字计算机的持续发展而不断增长。
instruction set 指令集
III. Hardware硬件
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 microcomputer with enhanced graphics and communications capabilities that make it especially useful for office work; the minicomputer, generally too expensive for personal use, with capabilities suited to a business, school, or laboratory; and the mainframe 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).
现代数字计算机无论大小,在概念上都是相似的。不过,根据基本开销和性能,它们可以分为以下几个类别:个人计算机或微型计算机,一种成本相对较低的机器,通常为台式机大小尽管"笔记本电脑"小到可以放入公文包,"掌上电脑"甚至可以放入口袋);工作站,是具备增强图形处理与通信能力的微型计算机,对于办公工作特别有用;小型计算机,对于个人使用来说通常太过昂贵,其性能适用于企业、学校或实验室;大型主机计算机,是体积庞大、价格昂贵的设备,能够满足大型企业、政府部门、科研机构等机构的需求(其中最大、最快的被称为超级计算机)。
conceptually /kənˈseptjuəli/ad. 概念上
microcomputer /ˈmaikrəukəmˌpjuːtə/n. 微型计算机
desktop /ˈdesktɔp/a. 桌面的;台式(计算机)的
laptop /ˈlæptɔp/n. 膝上型计算机
palmtop /ˈpɑːmtɔp/n. 掌上型计算机
workstation /ˈwəːkˌsteiʃən/n. 工作站
minicomputer /ˈminikəmˌpjuːtə/n. 小型计算机
mainframe /ˈmeinfreim/n. 主机,大型机
supercomputer /ˈsjuːpəkəmˌpjuːtə/n. 超级计算机,巨型计算机
A digital computer is not a single machine: rather, it is a system composed of five distinct elements: (1) a central processing unit; (2) input devices; (3) memory storage devices; (4) output devices; and (5) a communications network, called a bus, which links all the elements of the system and connects the system to the external world.
数字计算机并非单一的机器:相反,它是一个由五个不同的组成部分构成的系统:(1) 中央处理器;(2) 输入设备;(3) 存储设备;(4) 输出设备;以及 (5) 一个称为总线的通信网络,它连接系统的所有组成部分,并将系统与外部世界相连。
central processing unit 中央处理器
bus /bʌs/n. 总线
单词打卡

更多推荐


所有评论(0)