EOJ 2986~2990 2013年编程实践课程师范班第2次上机考试

2023-10-05 14:59

本文主要是介绍EOJ 2986~2990 2013年编程实践课程师范班第2次上机考试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

简单模拟题,主要是给编程实践没过的同学写的,希望能KO了它!

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2986

2986 计算2的N次方

#include <stdio.h>
#define  LL long long LL a[64];
void init()
{a[0] = 1;for(int i=1; i<=63; i++){a[i] = a[i-1]*2;}}
int main()
{int cas;init();scanf("%d", &cas);for(int i=0; i<cas; i++){int n;scanf("%d", &n);printf("case #%d:\n%lld\n", i, a[n]);}return 0;
}

 

 

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2987

 

2987 判断ip 

注意本题输入格式的小技巧,其他如:scanf("%s%c", str, chr)可以连续读字符串,到chr=‘\n’时停止读入。

另外如果刚兴趣,可以了解一下sprintf()。

#include <stdio.h>int main()
{int a,b,c,d;int cas;scanf("%d" ,&cas);for(int i=0; i<cas; i++){scanf("%d.%d.%d.%d" ,&a, &b, &c, &d);printf("case #%d:\n", i);if(a < 0 || a > 255){printf("No %d %d\n", 0, a);continue;}if(b < 0 || b > 255){printf("No %d %d\n", 1, b);continue;}if(c < 0 || c > 255){printf("No %d %d\n", 2, c);continue;}if(d < 0 || d > 255){printf("No %d %d\n", 3, d);continue;}printf("Yes\n");}return 0;
}

 

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2988

2988 密码产生器

#include <stdio.h>
char a[105];
int b[7];
int main(){int cas;scanf("%d", &cas);for(int i=0; i<cas; i++){scanf("%s" ,a);for(int j=0; j<6; j++)b[j] = 0;for(int j=0; a[j]!='\0'; j++){		b[j%6] += a[j];}printf("case #%d:\n", i);for(int j=0; j<6; j++){printf("%d", b[j]%10);}printf("\n");	}return 0;
}


 

 

 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2989

2989 字符串重排

按"NBA"输出,个数 不够时不输出。

#include <stdio.h>
char s[10005];
int a,b,c;
int main()
{int cas;scanf("%d" ,&cas);for(int i=0 ;i<cas; i++){scanf("%s", s);a = b = c;for(int j=0; s[j]!='\0'; j++){if(s[j] == 'N')a++;if(s[j] == 'B')b++;if(s[j] == 'A')c++;		 }printf("case #%d:\n", i);int d = 0;while(a || b || c){if(d % 3 == 0){if(a > 0){printf("N");a --;}}else if(d % 3 == 1){if(b > 0){printf("B");b --;}}else if(d % 3 == 2){if(c > 0){printf("A");c --;}}d ++;}printf("\n");}return 0;
}


 

http://acm.cs.ecnu.edu.cn/problem.php?problemid=2990

2990 文献排序

qsort:http://blog.163.com/justly@yeah/blog/static/121037000200952982531680/

sort :http://www.cplusplus.com/reference/algorithm/sort/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std; 
char s[205][205];
int cmp(const void * a, const void *  b)
{//(char*)(a)char s1[205], s2[205];int i;strcpy(s1, (char*)(a));strcpy(s2, (char*)(b));for(i=0;s1[i]!='\0'; i++){if(s1[i] >= 'A' && s1[i] <= 'Z')s1[i] = s1[i] - 'A' + 'a';}for(i=0;s2[i]!='\0'; i++){if(s2[i] >= 'A' && s2[i] <= 'Z')s2[i] = s2[i] - 'A' + 'a';}return strcmp(s1,s2);
}
int main()
{int cas;//freopen("in", "r", stdin);scanf("%d" ,&cas);//getchar();for(int i=0; i<cas; i++){int n;scanf("%d\n", &n);for(int j=0; j<n; j++){gets(s[j]);for(int k=0; s[j][k]!='\0'; k++){//if(s[j][k] >= 'A' && s[j][k] <= 'Z')//{//s[j][k] = s[j][k]-'A'+'a';//}}//puts(s[j]);}printf("case #%d:\n", i);qsort(s, n, sizeof(char[205]), cmp);for(int j=0; j<n ;j++)puts(s[j]);}	return 0;
}


 

这篇关于EOJ 2986~2990 2013年编程实践课程师范班第2次上机考试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/151450

相关文章

Spring Security简介、使用与最佳实践

《SpringSecurity简介、使用与最佳实践》SpringSecurity是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架,本文给大家介绍SpringSec... 目录一、如何理解 Spring Security?—— 核心思想二、如何在 Java 项目中使用?——

MySQL的JDBC编程详解

《MySQL的JDBC编程详解》:本文主要介绍MySQL的JDBC编程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录前言一、前置知识1. 引入依赖2. 认识 url二、JDBC 操作流程1. JDBC 的写操作2. JDBC 的读操作总结前言本文介绍了mysq

防止Linux rm命令误操作的多场景防护方案与实践

《防止Linuxrm命令误操作的多场景防护方案与实践》在Linux系统中,rm命令是删除文件和目录的高效工具,但一旦误操作,如执行rm-rf/或rm-rf/*,极易导致系统数据灾难,本文针对不同场景... 目录引言理解 rm 命令及误操作风险rm 命令基础常见误操作案例防护方案使用 rm编程 别名及安全删除

C++统计函数执行时间的最佳实践

《C++统计函数执行时间的最佳实践》在软件开发过程中,性能分析是优化程序的重要环节,了解函数的执行时间分布对于识别性能瓶颈至关重要,本文将分享一个C++函数执行时间统计工具,希望对大家有所帮助... 目录前言工具特性核心设计1. 数据结构设计2. 单例模式管理器3. RAII自动计时使用方法基本用法高级用法

PHP应用中处理限流和API节流的最佳实践

《PHP应用中处理限流和API节流的最佳实践》限流和API节流对于确保Web应用程序的可靠性、安全性和可扩展性至关重要,本文将详细介绍PHP应用中处理限流和API节流的最佳实践,下面就来和小编一起学习... 目录限流的重要性在 php 中实施限流的最佳实践使用集中式存储进行状态管理(如 Redis)采用滑动

ShardingProxy读写分离之原理、配置与实践过程

《ShardingProxy读写分离之原理、配置与实践过程》ShardingProxy是ApacheShardingSphere的数据库中间件,通过三层架构实现读写分离,解决高并发场景下数据库性能瓶... 目录一、ShardingProxy技术定位与读写分离核心价值1.1 技术定位1.2 读写分离核心价值二

深入浅出Spring中的@Autowired自动注入的工作原理及实践应用

《深入浅出Spring中的@Autowired自动注入的工作原理及实践应用》在Spring框架的学习旅程中,@Autowired无疑是一个高频出现却又让初学者头疼的注解,它看似简单,却蕴含着Sprin... 目录深入浅出Spring中的@Autowired:自动注入的奥秘什么是依赖注入?@Autowired

MySQL分库分表的实践示例

《MySQL分库分表的实践示例》MySQL分库分表适用于数据量大或并发压力高的场景,核心技术包括水平/垂直分片和分库,需应对分布式事务、跨库查询等挑战,通过中间件和解决方案实现,最佳实践为合理策略、备... 目录一、分库分表的触发条件1.1 数据量阈值1.2 并发压力二、分库分表的核心技术模块2.1 水平分

SpringBoot通过main方法启动web项目实践

《SpringBoot通过main方法启动web项目实践》SpringBoot通过SpringApplication.run()启动Web项目,自动推断应用类型,加载初始化器与监听器,配置Spring... 目录1. 启动入口:SpringApplication.run()2. SpringApplicat

Python异步编程之await与asyncio基本用法详解

《Python异步编程之await与asyncio基本用法详解》在Python中,await和asyncio是异步编程的核心工具,用于高效处理I/O密集型任务(如网络请求、文件读写、数据库操作等),接... 目录一、核心概念二、使用场景三、基本用法1. 定义协程2. 运行协程3. 并发执行多个任务四、关键