基础106:I have a very simple problem for you. Given two integers A and B, your job is to calculate the Sum of A + B.
cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int n;
scanf("%d",&n);
getchar();
int count = 1;
while(n){
//特别大的行数时
char hang[3000];
int ch;
int HangLen=0;
while( (ch = getchar()) !=EOF){
if(ch == '\n')break;
else hang[HangLen++] = ch;
}
hang[HangLen] = '\0';
int a[2000],b[2000];
//1. 将数取到a和b中
int lenA=0,lenB=0;
for(int i=strlen(hang)-1,changeA=0;i>=0;i--){
if(hang[i] == ' '){
changeA=1;
continue;
}
if(changeA){
a[lenA] = (hang[i] - '0');
lenA++;
}
else{
b[lenB] = (hang[i] - '0');
lenB++;
}
}
//验证
// for(int i=0;i<lenA;i++){
// printf("%d",a[i]);
// }
// printf("\n");
// for(int i=0;i<lenB;i++){
// printf("%d",b[i]);
// }
// printf("\n");
printf("Case %d:\n",count++);
for(int i=lenA-1;i>=0;i--){
printf("%d",a[i]);
}
printf(" + ");
for(int i=lenB-1;i>=0;i--){
printf("%d",b[i]);
}
printf(" = ");
if(lenA>=lenB){
//运算
for(int i=0;i<lenB;i++){
a[i] += b[i];
if(a[i]>9){
int jin=1;
int index=i;
while(jin){
if(index==lenA-1){//没有更高位时
a[index]-=10;
lenA++;
a[index+1]=1;
jin=0;
}
else{
a[index]-=10;
a[index+1]+=1;
if(a[index+1]>9)index++;
else jin=0;
}
}
}
}
//输出
for(int i=lenA-1;i>=0;i--){
printf("%d",a[i]);
}
printf("\n");
printf("\n");
}
else{
for(int i=0;i<lenA;i++){
b[i] += a[i];
if(b[i]>9){
int jin=1;
int index=i;
while(jin){
if(index==lenB-1){//没有更高位时
b[index]-=10;
lenB++;
b[index+1]=1;
jin=0;
}
else{
b[index]-=10;
b[index+1]+=1;
if(b[index+1]>9)index++;
else jin=0;
}
}
}
}
//输出
for(int i=lenB-1;i>=0;i--){
printf("%d",b[i]);
}
printf("\n");
printf("\n");
}
n--;
}
system("pause");
}
基础107:某天、小晨在路上背着单词,突遇一外星人,外星人对小晨很感兴趣,为了考验小晨的智商,就向小晨提问简单加法,由于外星人使用16进制,所以,小晨必须用16进制回答。
首先输入一个整数T,以下T行,每行两个16进制数字,每行一个16进制数,为求出的两数之和。
cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int n;
scanf("%d",&n);
getchar();
while(n){
char data[15];
fgets(data,sizeof(data),stdin);
data[ strcspn(data,"\n") ] = '\0';
int a=0,b=0;
for(int i=0,change=0;i<strlen(data);i++){
if(data[i] == ' '){
change=1;
continue;
}
int temp=0;
if(data[i]>='0'&&data[i]<='9')temp=(data[i] - '0');
else{
switch(data[i]){
case ('a'): temp=10;break;
case ('b'): temp=11;break;
case ('c'): temp=12;break;
case ('d'): temp=13;break;
case ('e'): temp=14;break;
case ('f'): temp=15;break;
}
}
if(!change){
a=a*16+temp;
}
else{
b=b*16+temp;
}
}
//printf("%d\n",a);
//printf("%d\n",b);
a += b;
//表示
char ans[10];
int len=0;
while(a>0){
ans[len] = a%16;
len++;
a/=16;
}
for(int i=len-1;i>=0;i--){
if(!(ans[i]>=10))printf("%d",ans[i]);
else{
switch (ans[i]){
case (10): printf("a");break;
case (11): printf("b");break;
case (12): printf("c");break;
case (13): printf("d");break;
case (14): printf("e");break;
case (15): printf("f");break;
}
}
}
printf("\n");
n--;
}
}
//4b0d 4887
//直接做加法运算
- 字符串中结束符不算字符串长度
基础108:跟据一个正整数n,求出从1,000开始从小到大的第n个纯粹素数。
cpp
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int n;
while( scanf("%d",&n) != EOF){
int count =1;
int num=1013;
while(count < n){
num+=2;
//判断 num
int yes=1;
//逐位检测
int temp=num;
while(temp>0){
if(temp<3){
yes=0;break;
}
for(int i=3;i<=temp/2;i+=2){
if(temp%i==0){
//printf("失败:%d与%d\n",temp,i);
yes=0;
break;
}
}//判断
if(yes==0)break;
//更新temp
int minus=1;
while(temp/minus>9)minus*=10;
while(temp>=minus)temp-=minus;
}
if(yes)count++;
}
printf("%d\n",num);
}
}
Software engineering is an area of software development in which computer scientists and engineers study methods and tools that facilitate the efficient development of correct, reliable, and robust computer programs. Research in this branch of computer science considers all the phases of the software life cycle, which begins with a formal problem specification, and progresses to the design of a solution, its implementation as a program, testing of the program, and program maintenance. Software engineers develop software tools and collections of tools called programming environments to improve the development process. For example, tools can help to manage the many components of a large program that is being written by a team of programmers.
- specification 规格/规范/规约, consider 涵盖
- 软件工程学是软件开发的一个领域,在该领域中,计算机科学家和工程师研究用以促进对有效开发正确、可靠且健壮的计算机程序方法和工具。作为计算机科学的一个分支,研究涵盖 到软件的生命周期的所有阶段,从正式的问题规约 开始到解决方案的设计过程,将其实现为程序,测试开发的程序和程序维护。软件工程师开发软件工具和叫做编程环境的工具集来改良开发过程。例如,一个正在由程序员团队开发的大型程序,工具能帮助管理该程序的许多组件。
Computer architecture is the design and analysis of new computer systems. Computer architects study ways of improving computers by increasing their speed, storage capacity, and reliability, and by reducing their cost and power consumption. Computer architects develop both software and hardware models to analyze the performance of existing and proposed computer designs, and then use this analysis to guide the development of new computers. They are often involved with the engineering of a new computer because the accuracy of their models depends on the design of the computer's circuitry. Many computer architects are interested in developing computers that are specialized for particular applications such as image processing, signal processing, or the control of mechanical systems. The optimization of computer architecture to specific tasks often yields higher performance, lower cost, or both¹.
- 计算机架构是对新的计算机系统的设计与分析。计算机架构师研究改良计算机的方式通过提升运行速度、存储容量和可信度以及减少成本和功耗 。计算机架构师同时开发软硬件模型来分析已有和已被提出的计算机设计的性能,并利用该分析来引导新计算机的开发。他们通常参与 新计算机的工程设计 相关,因为他们的模型准确度取决于这台计算机的电路设计。许多计算机架构师对面向特定应用的特殊的计算机开发感兴趣,例如图像处理、信号处理、或是机械系统控制。为了特定任务而改良的计算机架构常常带来更高的性能或更低的成本或两者皆有。
Artificial intelligence (Al) research seeks to enable computers and machines to mimic human intelligence and sensory processing ability, and models human behavior with computers to improve our understanding of intelligence. The many branches of AI research include machine learning, inference, cognition, knowledge representation, problem solving, casebased reasoning, natural language understanding, speech recognition, computer vision, and artificial neural networks.
- mimic 模仿,sensory 感觉的/感官的,cognition 认知,model 建模
- 人工智能研究寻求让计算机和机器能够模仿人类智能和感知处理能力,以及通过计算机对人类行为进行建模 来提高我们对智慧的理解。AI研究的许多分支包括机器学习,推理 ,认知,知识表示 ,问题求解 ,基于案例的推理,自然语言理解,语音识别,计算机视觉,和人工神经网络。