100000574 - 《算法笔记》2.10小节——C/C++快速入门->黑盒测试

本文详细介绍了使用C/C++进行各种输入输出练习的方法,包括EOF、N--、break等不同类型的多点输入测试,以及如何处理多个数字的加法运算。

《算法笔记》2.10小节——C/C++快速入门->黑盒测试

1000 Problem A A+B 输入输出练习I

//while...EOF型 多点输入测试
#include <stdio.h>
//#include<iostream>
//using namespace std;

int main() {
	int a, b;
	//while (scanf("%d %d", &a, &b) != EOF) {	
	while (~scanf("%d %d", &a, &b) ) {
		printf("%d\n", a + b);
	}
	//while(cin>>a>>b)
	//{
	//	cout << a + b << endl;
	//}
	return 0;
}

1001 Problem B A+B 输入输出练习II

//while(N--)型 多点输入测试
#include <stdio.h>

int main() {
	int a, b;
	int N;
	scanf("%d", &N);
	
	while (N--) {
		scanf("%d%d", &a, &b);
		printf("%d\n", a + b);
	}

	return 0;
}

1002 Problem C A+B 输入输出练习III

//while...break型 多点输入测试
#include <stdio.h>

int main() {
	int a, b;

	//while (scanf("%d%d", &a, &b)!=EOF) {
	//	if (a == 0 && b == 0) break;
	//	printf("%d\n", a + b);
	//}

	while (scanf("%d %d", &a, &b), a || b) {	//a || b 即 a!=0 || b!=0
		printf("%d\n", a + b);
	}

	return 0;
}

1003 Problem D A+B 输入输出练习IV

#include <stdio.h>

int main() {
	int num,a;

	while (scanf("%d", &num)!=EOF) {
		if (num==0) break;
		int sum = 0;
		while (num--) {
			scanf("%d", &a);
			sum += a;
		}
		printf("%d\n", sum);
	}

	return 0;
}

1004 Problem E A+B 输入输出练习V

#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);

	while (N--) {
		int num;
		scanf("%d", &num);
		int sum = 0, a = 0;
		while (num--) {
			scanf("%d", &a);
			sum += a;
		}
		printf("%d\n", sum);
	}

	return 0;
}

1005 Problem F A+B 输入输出练习VI

#include <stdio.h>

int main() {
	int num;

	while (scanf("%d",&num)!=EOF) {
		int a = 0, sum = 0;
		while (num--) {
			scanf("%d", &a);
			sum += a;
		}
		printf("%d\n", sum);
	}

	return 0;
}

1006 Problem G A+B 输入输出练习VII

#include <stdio.h>

int main() {
	int a,b;

	while (scanf("%d%d",&a,&b)!=EOF) {
		int sum;
		sum = a+b;
		printf("%d\n\n", sum);
	}
	return 0;
}

1007 Problem H A+B 输入输出练习VIII

#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);

	while (N--) {
		int num;
		scanf("%d", &num);
		int sum = 0, a = 0;
		while (num--) {
			scanf("%d", &a);
			sum += a;
		}
		printf("%d\n\n", sum);
	}

	return 0;
}
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <name>Timo后台管理系统</name> <description>快速搭建后台管理的系统</description> <groupId>com.linln</groupId> <artifactId>timo</artifactId> <version>2.0.3</version> <packaging>pom</packaging> <modules> <module>admin</module> <module>common</module> <module>component</module> <module>devtools</module> <module>modules</module> </modules> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.7</version> <relativePath/> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <!--shiro权限管理框架版本:component.shiro--> <shiro.version>1.9.0</shiro.version> <lombok.version>1.18.24</lombok.version> <ehcache.version>2.10.9.2</ehcache.version> <mysql.connector.version>5.1.46</mysql.connector.version> <jsoup.version>1.14.3</jsoup.version> <!--shiro模板视图权限标签扩展:component.thymeleaf--> <thymeleaf-shiro.version>2.1.0</thymeleaf-shiro.version> <!--excel工具框架版本:component.excel--> <poi.version>4.1.2</poi.version> <!--jwt处理框架版本:component.jwt--> <jwt.version>3.19.1</jwt.version> <!--swagger-knife4j接口文档页面:component.jwt--> <knife4j.version>3.0.3</knife4j.version> <google.findbugs.version>3.0.1</google.findbugs.version> <skipTests>true</skipTests> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <!--spring data jpa持久层框架--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!--mysql连接驱动--> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.connector.version}</version> <scope>runtime</scope> </dependency> <!--lombok语法糖--> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>${lombok.version}</version> <optional>true</optional> </dependency> <!--ehcache缓存框架--> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> <version>${ehcache.version}</version> </dependency> <!--html解析工具,处理xss攻击--> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>${jsoup.version}</version> </dependency> <!--knife4j 接口文档--> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>${knife4j.version}</version> </dependency> <!--解决编译时javax.annotation.meta.When不存在问题--> <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>annotations</artifactId> <version>${google.findbugs.version}</version> </dependency> </dependencies> <!--多环境配置--> <profiles> <!--开发环境--> <profile> <id>dev</id> <activation> <!--默认配置--> <activeByDefault>true</activeByDefault> </activation> <properties> <profile.name>dev</profile.name> </properties> </profile> <!--生产环境--> <profile> <id>prod</id> <properties> <profile.name>prod</profile.name> </properties> </profile> </profiles> </project>
最新发布
06-28
<think>根据提供的pom.xml文件,这是一个Maven多模块项目,父项目为timo,包含多个子模块:admin,common,component,devtools, modules。父项目使用了Spring Boot2.6.7,并管理了多个依赖和属性。分析需求:用户可能希望了解如何基于这个pom.xml构建项目,或者如何添加新的模块,或者如何配置多环境等。由于问题不明确,我将根据常见的需求提供一些指导。常见操作:1.如何构建整个项目?2.如何添加一个新的模块?3.多环境配置的使用(dev和prod)?4.如何运行项目?由于用户没有提出具体问题,我将根据pom.xml的内容,给出一个标准的构建和运行步骤,并解释多环境配置的使用。步骤1:构建整个项目在项目根目录(即pom.xml所在的目录)执行以下命令:```bashmvn cleaninstall```步骤2:运行项目(假设我们要运行admin模块,因为通常admin是主应用)进入admin模块目录,然后使用SpringBoot Maven插件运行:```bashcdadminmvn spring-boot:run-Pdev#使用dev环境运行```或者使用生产环境配置: ```bashmvnspring-boot:run -Pprod```步骤3:添加新模块假设要添加一个名为`new-module`的模块:1.在项目根目录下创建`new-module`文件夹。2.在`new-module`文件夹中创建`pom.xml`,内容参考其他模块,至少包含:```xml<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.linln</groupId><artifactId>timo</artifactId><version>2.0.3</version></parent><artifactId>new-module</artifactId><packaging>jar</packaging></project>```3.在父项目的pom.xml的`<modules>`部分添加:```xml<module>new-module</module>```步骤4:多环境配置的使用在SpringBoot项目中,多环境配置文件通常命名为`application-{profile}.properties`或`application-{profile}.yml`。在`src/main/resources`目录下,我们可能有:-application-dev.properties(开发环境)- application-prod.properties(生产环境)在运行时,通过`spring.profiles.active`属性指定环境。在Maven命令中,我们使用`-P`参数来激活Maven的profile,然后Maven的profile可以设置`spring.profiles.active`。但注意,在pom.xml中,我们定义的profile是Maven的profile,它可以通过资源过滤来传递属性,或者通过`-D`参数传递。更常见的做法是在SpringBoot的application.properties中设置`spring.profiles.active=@profile.name@`,然后在Maven资源过滤时替换。但是在这个pom.xml中,我们没有看到资源过滤的配置。因此,可能需要额外配置。或者,我们可以在运行应用时直接指定Spring的profile: ```bashmvn spring-boot:run-Dspring-boot.run.profiles=dev```由于pom.xml中已经定义了Maven的profile,并且每个profile有一个`profile.name`属性,我们可以通过资源过滤将`profile.name`的值传递给SpringBoot的配置文件。但是,观察这个pom.xml,并没有配置资源过滤。因此,如果项目中没有配置,那么可能需要手动配置资源过滤,或者使用上述的命令行参数方式。如果需要配置资源过滤,可以在pom.xml的build部分添加:```xml<build><resources><resource><directory>src/main/resources</directory><filtering>true</filtering><includes><include>application.properties</include></includes></resource></resources> </build>```然后在`application.properties`中设置:```spring.profiles.active=@profile.name@```这样,当使用`mvn install-Pdev`时,`@profile.name@`会被替换为`dev`。但是,请注意,这个pom.xml没有配置build部分,因此默认不会进行资源过滤。如果需要,可以添加。由于用户的问题不明确,我将提供一些常见的相关问题和解答。如果用户有具体问题,可以进一步提问。鉴于以上,我将提供如何运行这个项目的示例代码(实际上是命令)和解释。注意:代码部分使用markdown格式包裹,但由于是命令,所以使用bash代码块。示例:使用Maven构建并运行项目(以admin模块为例,使用dev环境)</think>根据提供的 `pom.xml` 文件,这是一个基于 Spring Boot 2.6.7 的多模块 Maven 项目,用于构建 "Timo后台管理系统"。以下是关键分析和优化建议: ### 关键分析 1. **项目结构** ```xml <modules> <module>admin</module> <module>common</module> <module>component</module> <module>devtools</module> <module>modules</module> </modules> ``` - `admin`: 主应用模块 - `common`: 公共工具和基础类 - `component`: 核心组件(如 Shiro、Excel 等) - `devtools`: 开发工具支持 - `modules`: 业务功能模块 2. **依赖管理** - 核心依赖:Spring Boot Web、Data JPA、Validation - 安全框架:Apache Shiro 1.9.0 - 工具集:Lombok、Ehcache、Jsoup (防XSS)、Knife4j (API文档) - 数据库:MySQL Connector 3. **多环境配置** ```xml <profiles> <profile> <id>dev</id> <!-- 默认激活 --> </profile> <profile> <id>prod</id> <!-- 生产环境 --> </profile> </profiles> ``` ### 优化建议与示例代码 #### 1. 添加资源过滤支持多环境 在 `<build>` 中增加资源过滤,使 `application-{profile}.yml` 自动生效: ```xml <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <!-- 启用变量替换 --> <includes> <include>application*.yml</include> </includes> </resource> </resources> </build> ``` #### 2. 统一依赖版本管理 将第三方依赖版本移至 `<dependencyManagement>` 避免冲突: ```xml <dependencyManagement> <dependencies> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>${shiro.version}</version> </dependency> <!-- 其他组件统一管理 --> </dependencies> </dependencyManagement> ``` #### 3. 增强安全配置(XSS过滤示例) 在 `common` 模块添加全局 XSS 过滤器: ```java // XssFilter.java @WebFilter(urlPatterns = "/*") public class XssFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; // 使用Jsoup清理用户输入 String sanitizedInput = Jsoup.clean(request.getParameter("input"), Safelist.basic()); // 将清理后的数据放入请求属性 request.setAttribute("safeInput", sanitizedInput); chain.doFilter(new XssRequestWrapper(request), res); } } // 在启动类添加注解 @ServletComponentScan // 启用Filter扫描 ``` #### 4. 多环境配置示例 `src/main/resources/application-dev.yml`: ```yaml server: port: 8080 spring: datasource: url: jdbc:mysql://localhost:3306/timo_dev username: dev_user password: dev_pass ``` `src/main/resources/application-prod.yml`: ```yaml server: port: 80 spring: datasource: url: jdbc:mysql://prod-db:3306/timo_prod username: prod_user password: ${DB_PASSWORD} # 从环境变量读取 ``` ### 项目启动命令 ```bash # 开发环境 mvn spring-boot:run -P dev # 生产环境 (传递密码参数) mvn spring-boot:run -P prod -Dspring-boot.run.arguments=--DB_PASSWORD=secret123 ``` ### 关键解释 1. **资源过滤 (`<filtering>true</filtering>)** 允许在配置文件中使用 Maven 变量(如 `@profile.name@`),构建时自动替换为实际值。 2. **XSS 防御原理** `Jsoup.clean()` 通过 `Safelist` 限制允许的 HTML 标签,过滤 `<script>` 等危险内容。 3. **多环境切换机制** `-P` 参数激活 Maven Profile,Spring Boot 会自动加载对应的 `application-{profile}.yml` 配置。 4. **依赖管理优势** 子模块无需指定组件版本,避免版本冲突,确保所有模块使用统一依赖版本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值