东华复试OJ每日3题打卡·复盘103~105

基础103:输入一行数字,如果我们把这行数字中的'5'都看成空格,那么就得到一行用空格分割的若干非负整数,对这些分割得到的整数,依从小到大的顺序排序输出。

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>



int main(){
    int circle;
    scanf("%d",&circle);
    getchar();
  //0051231232050775  
    while(circle){
        char Hang[1000];
        fgets(Hang,sizeof(Hang),stdin);
        
        Hang[strcspn(Hang,"\n")] = '\0';

        //算法
        //数字的最大值为10亿,在int的保存范围之内,故可以用int数组来保存
		int nums[500] ;
		int numLen=0;
		int tempnum=0;
		int had=0;
		 for(int i=0;i<strlen(Hang);i++){
			if(Hang[i]=='5'){
				if(had){
					nums[numLen] = tempnum;
					numLen++;
					had=0;
					tempnum=0;
				}
			}
			else if(i==strlen(Hang)-1  ){
				if(Hang[i]!='5'){
					tempnum = tempnum*10 + (Hang[i] - '0');
					had=1;
				}
				if(had){
					nums[numLen] = tempnum;
					numLen++;
					had=0;
					tempnum=0;
				}
			}
			else{
				tempnum = tempnum*10 + (Hang[i] - '0');
				had=1;
			}
			
		}
		//使其有序
		 
		for(int i=0; i<numLen-1; i++){
		    for(int j=0; j<numLen-1-i; j++){ 
		        if(nums[j] > nums[j+1]){
		        	int temp = nums[j+1];
		        	nums[j+1] = nums[j];
		        	nums[j] = temp;
				}
			}
		}

		 
		for(int i=0;i<numLen;i++){
			printf("%d", nums[i]);
			if(i!=numLen-1)printf(" ");
			
		}
		printf("\n");

        
        
        circle--;
        
        
    }//测试数据循环
    
}

基础104:给你两个非负实数A和B,如果A等于B,输出 "YES", 否则输出"NO"

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int loop=0;
    scanf("%d",&loop);
    getchar();
    while(loop){
    	
        char Hang[2000];
        fgets(Hang,sizeof(Hang),stdin);
        Hang[ strcspn(Hang,"\n")] = '\0';

        //1.把每个数分为两个部分,整数和小数,分别比对整数部分和小数部分
        int aZheng=0,aXiaoShu=0;
        int bZheng=0,bXiaoShu=0;
        int change=0;
        int zheng=1;
        for(int i=0;i<strlen(Hang);i++){
            if(Hang[i] == '.'){
            	zheng=0;
            	continue;
			}
            if(Hang[i] == ' '){
                change=1;
                zheng=1;
                continue;
            }
            if(change){
                if(zheng)bZheng = bZheng*10 + (Hang[i] - '0') ;
                else bXiaoShu = bXiaoShu*10 + (Hang[i] - '0') ;
            }
            else{
                if(zheng)aZheng = aZheng*10 + (Hang[i] - '0') ;
                else aXiaoShu = aXiaoShu*10 + (Hang[i] - '0') ;
            }
        }
        
        //小数需要特殊处理末尾0
        while(aXiaoShu%10==0&&aXiaoShu!=0)aXiaoShu/=10;
        while(bXiaoShu%10==0&&aXiaoShu!=0)bXiaoShu/=10;

        
        //printf("a=%d.%d\n",aZheng,aXiaoShu);
        //printf("b=%d.%d\n",bZheng,bXiaoShu);
        if(aZheng == bZheng && aXiaoShu==bXiaoShu)printf("YES\n");
        else printf("NO\n");
        
        
        loop--;
    }
    
}

基础105:在寻找回文时不用理睬那些标点符号、空格(但应该保留下来以便做为答案输出),只用考虑字母'A'-'Z'和'a'-'z'。要你寻找的最长的回文的文章是一个不超过20,000个字符的字符串。输入一个不超过20,000个字符的文件。

cpp 复制代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//Confucius say: Madam, I'm Adam.
int main(){
    char Hang[2000];
    int totalLen=0;
    int ch;
    while( (ch = getchar()) != EOF ){
    	Hang[totalLen++] = ch;
	}
    Hang[totalLen++] = '\0';
    

    char data[2000];
    int len=0;
    
    int Change[2000];
    
    for(int i=0,j=0;i<strlen(Hang);i++){
        if(Hang[i]>='A'&&Hang[i]<='Z'){
            data[j] = Hang[i];
            Change[j]=i;//保存起始下标 
            //printf("%c",data[j]);
            j++;
            len++;
            
        }
        else if( Hang[i]>='a'&&Hang[i]<='z' ){
            data[j] = Hang[i] -32 ;
            Change[j]=i;//保存起始下标 
           // printf("%c",data[j]);
            //printf("%d=%c,",j,data[j]);
            j++;
            len++;
        }
    }
    //printf("\n");
    
    //遍历data找到回文
    int ansIndex=0;
    int ansLen=0;
	for(int i=0;i<len;i++){
		int yes=1;
		int Wei=len-1;//尾部 
		int templen=0;
		while(Wei>i){//不断从尾部遍历找到该头为起始的回文 
			yes=1;
			templen=0;
			for(int j=Wei,k=i;j>i;k++,j--){
				if(data[k] != data[j]){
					yes=0;
					break;
				}
				else{
					templen++;
				}
			}
			if(yes){
				if(templen>ansLen){
					ansIndex=i;
					ansLen=Wei-i+1;
					break;
				}	
			}
			Wei--;
		}
		
	} 
	
	
	printf("%d\n",ansLen);
	
	for(int i=Change[ansIndex];i<=Change[ansIndex+ansLen-1];i++){
		printf("%c",Hang[i]);
	}
	printf("\n");
    
    
}
  • 输入数据为字符串直接投入时,使用(ch = getchar()) != EOF,字符一个一个的接收,int ch是因为getchar返回ASCII码值,若非ASCII编码则为-1。

It might seem that the predictable nature of computers makes experimentation unnecessary because the outcome of experiments should be known in advance. But when computer systems and their interactions with the natural world become sufficiently complex, unforeseen behavior can result. Experimentation and the traditional scientific method are thus key parts of computer science.

  • 计算机的可预测性似乎使得 使得实验非必要,因为实验结果理应可以被提前知晓。但是当计算机系统以及与现实世界的交互变得足够复杂,会导致不可预见的行为。因此实验和传统科学的方法成为计算机科学的关键部分。

Computer science can be divided into four main fields: software development, computer architecture (hardware), human-computer interfacing (the design of the most efficient ways for humans to use computers), and artificial intelligence (the attempt to make computers behave intelligently). Software development is concerned with creating computer programs that perform efficiently. Computer architecture concerned with developing optimal hardware for specific computational needs. The areas of artificial intelligence (AI2) and human-computer interfacing often involve the development of both software and hardware to solve specific problems.

  • is concerned with 涉及,optimal 最佳的
  • 计算机科学可分为四个主要领域:软件开发、计算机架构、人机交互 和人工智能。软件开发与创造运作高效的计算机程序有关。计算机架构涉及为特定的计算需要开发最优的硬件。人工智能和人机接口常常 涉及解决特定问题的软硬件同时开发。

In developing computer software, computer scientists and engineers study various areas and techniques of software design, such as the best types of programming languages and algorithms to use in specific programs, how to efficiently store and retrieve information, and the computational limits of certain software-computer combinations. Software designers must consider many factors when developing a program. Often, program performance in one area must be sacrificed for the sake of the general performance of the software. For instance, since computers have only a limited amount of memory, software designers must limit the number of features they include in a program so that it will not require more memory than the system it is designed for can supply.

  • 在开发计算机软件过程 中,计算机科学家和工程师研究 各种各样的软件设计的各个 领域和技术,例如用于特定程序的最好的编程语言和用于特定程序的算法,如何高效储存和检索 信息,以及特定软件与计算机结合的计算局限性。在开发程序时,软件设计师必须考虑许多因素。通常,在某个方面 的程序性能必须做出 牺牲为了 该软件的整体 性能。例如,由于 计算机只有存储体容量的限制,软件设计师必须限制一个程序的包含的功能数量 来使其所需的存储空间少于不超过 设计得可适用的存储空间目标系统所能提供的容量
  • retrieve 检索, since 因为/由于
相关推荐
SuniaWang2 小时前
《Spring AI + 大模型全栈实战》学习手册系列 ·专题三:《Embedding 模型选型指南:从 MMTEB 排名到实际应用》
人工智能·学习·spring
问道飞鱼2 小时前
【Tauri框架学习】Windows 11 环境下 Tauri 开发环境安装与问题解决手册
windows·学习·tauri·开发环境
لا معنى له2 小时前
什么是Active Inference(主动推理)? ——学习笔记
笔记·学习
JicasdC123asd2 小时前
并行双分支瓶颈架构改进YOLOv26异构卷积核协同特征提取与残差学习双重突破
学习·yolo·架构
zhouping@2 小时前
JAVA学习笔记day06
java·笔记·学习
罗罗攀4 小时前
PyTorch学习笔记|张量的广播和科学运算
人工智能·pytorch·笔记·python·学习
CDA数据分析师干货分享4 小时前
汉江师范学院数据科学与大数据技术专业大二学生:CDA一级学习经验
大数据·经验分享·学习·数据分析·cda证书·cda数据分析师
SuniaWang4 小时前
《Spring AI + 大模型全栈实战》学习手册系列 · 专题四:《Ollama 模型管理与调优:让 AI 模型在低配服务器上流畅运行》
人工智能·学习·spring
冰水不凉4 小时前
cartographer源码阅读四-MapBuilder
学习·slam