《算法笔记》2.7小节——C/C++快速入门->指针 问题 B: C语言10.2

本文介绍了一种使用C语言指针实现的三个整数按从大到小排序的方法。通过定义指针变量并利用条件表达式,实现了输入三个整数后的自动排序输出。此方法有助于理解指针操作和条件判断在实际编程中的应用。

问题 B: C语言10.2

题目描述

输入a、b、c三个整数,按先大后小的顺序输出a、b和c。注意请使用指针变量的方式进行比较和输出。

输入

三个用空格隔开的整数a、b和c。

输出

按先大后小的顺序输出a、b和c,用空格隔开。
请注意行尾输出换行。

样例输入

9 0 10

样例输出

10 9 0
#include <cstdio>

int main() {
    int a, b, c;
    int *p = &a, *q = &b, *r = &c;
    scanf("%d %d %d", &a, &b, &c);
    printf("%d %d %d\n", (*p > *q ? *p : *q) > *r ? (*p > *q ? *p : *q) : *r,
           (*p > *q ? *p : *q) > *r ? ((*p > *q ? *q : *p) > *r ? (*p > *q ? *q : *p) : *r) : (*p > *q ? *p : *q),
           (*p > *q ? *q : *p) < *r ? (*p > *q ? *q : *p) : *r);
    return 0;
}
这个是完整源码 python实现 Flask,Vue 【python毕业设计】基于Python的Flask+Vue物业管理系统 源码+论文+sql脚本 完整版 数据库是mysql 本文首先实现了基于Python的Flask+Vue物业管理系统技术的发展随后依照传统的软件开发流程,最先为系统挑选适用的言语和软件开发平台,依据需求分析开展控制模块制做和数据库查询构造设计,随后依据系统整体功能模块的设计,制作系统的功能模块图、E-R图。随后,设计框架,依据设计的框架撰写编码,完成系统的每个功能模块。最终,对基本系统开展了检测,包含软件性能测试、单元测试和性能指标。测试结果表明,该系统能够实现所需的功能,运行状况尚可并无明显缺点。本文首先实现了基于Python的Flask+Vue物业管理系统技术的发展随后依照传统的软件开发流程,最先为系统挑选适用的言语和软件开发平台,依据需求分析开展控制模块制做和数据库查询构造设计,随后依据系统整体功能模块的设计,制作系统的功能模块图、E-R图。随后,设计框架,依据设计的框架撰写编码,完成系统的每个功能模块。最终,对基本系统开展了检测,包含软件性能测试、单元测试和性能指标。测试结果表明,该系统能够实现所需的功能,运行状况尚可并无明显缺点。本文首先实现了基于Python的Flask+Vue物业管理系统技术的发展随后依照传统的软件开发流程,最先为系统挑选适用的言语和软件开发平台,依据需求分析开展控制模块制做和数据库查询构造设计,随后依据系统整体功能模块的设计,制作系统的功能模块图、E-R图。随后,设计框架,依据设计的框架撰写编码,完成系统的每个功能模块。最终,对基本系统开展了检测,包含软件性能测试、单元测试和性能指标。测试结果表明,该系统能够实现所需的功能,运行状况尚可并无明显缺点。本文首先实现了基于Python的Flask+Vue物业管理系统技术的发
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- Note: A "Server" is not itself a "Container", so you may not define subcomponents such as "Valves" at this level. Documentation at /docs/config/server.html --> <Server port="8005" shutdown="SHUTDOWN"> <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <!-- Security listener. Documentation at /docs/config/listeners.html <Listener className="org.apache.catalina.security.SecurityListener" /> --> <!-- OpenSSL support using Tomcat Native --> <Listener className="org.apache.catalina.core.AprLifecycleListener" /> <!-- OpenSSL support using FFM API from Java 22 --> <!-- <Listener className="org.apache.catalina.core.OpenSSLLifecycleListener" /> --> <!-- Prevent memory leaks due to use of particular java/javax APIs--> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <!-- Global JNDI resources Documentation at /docs/jndi-resources-howto.html --> <GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> </GlobalNamingResources> <!-- A "Service" is a collection of one or more "Connectors" that share a single "Container" Note: A "Service" is not itself a "Container", so you may not define subcomponents such as "Valves" at this level. Documentation at /docs/config/service.html --> <Service name="Catalina"> <!--The connectors can use a shared executor, you can define one or more named thread pools--> <!-- <Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="150" minSpareThreads="4"/> --> <!-- A "Connector" represents an endpoint by which requests are received and responses are returned. Documentation at : HTTP Connector: /docs/config/http.html AJP Connector: /docs/config/ajp.html Define a non-SSL/TLS HTTP/1.1 Connector on port 8080 --> <Connector port="8080" protocol="HTTP/1.1" URIEncoding="UTF-8" connectionTimeout="20000" redirectPort="8443" maxParameterCount="1000" /> <!-- A "Connector" using the shared thread pool--> <!-- <Connector executor="tomcatThreadPool" port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxParameterCount="1000" /> --> <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2 This connector uses the NIO implementation. The default SSLImplementation will depend on the presence of the APR/native library and the useOpenSSL attribute of the AprLifecycleListener. Either JSSE or OpenSSL style configuration may be used regardless of the SSLImplementation selected. JSSE style configuration is used below. --> <!-- <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" maxThreads="150" SSLEnabled="true" maxParameterCount="1000" > <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" /> <SSLHostConfig> <Certificate certificateKeystoreFile="conf/localhost-rsa.jks" certificateKeystorePassword="changeit" type="RSA" /> </SSLHostConfig> </Connector> --> <!-- Define an AJP 1.3 Connector on port 8009 --> <!-- <Connector protocol="AJP/1.3" address="::1" port="8009" redirectPort="8443" maxParameterCount="1000" /> --> <!-- An Engine represents the entry point (within Catalina) that processes every request. The Engine implementation for Tomcat stand alone analyzes the HTTP headers included with the request, and passes them on to the appropriate Host (virtual host). Documentation at /docs/config/engine.html --> <!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1"> --> <Engine name="Catalina" defaultHost="localhost"> <!--For clustering, please take a look at documentation at: /docs/cluster-howto.html (simple how to) /docs/config/cluster.html (reference documentation) --> <!-- <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/> --> <!-- Use the LockOutRealm to prevent attempts to guess user passwords via a brute-force attack --> <Realm className="org.apache.catalina.realm.LockOutRealm"> <!-- This Realm uses the UserDatabase configured in the global JNDI resources under the key "UserDatabase". Any edits that are performed against this UserDatabase are immediately available for use by the Realm. --> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- SingleSignOn valve, share authentication between web applications Documentation at: /docs/config/valve.html --> <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> --> <!-- Access log processes all example. Documentation at: /docs/config/valve.html Note: The pattern used is equivalent to using pattern="common" --> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log" suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>
09-23
### server.xml 文件配置说明 #### 整体结构 server.xml 的整体结构包含 `<Server>`、`<Service>`、`<Connector>`、`<Engine>`、`<Host>` 和 `<Context>` 等核心元素。其基本结构如下: ```xml <Server> <Service> <Connector /> <Connector /> <Engine> <Host> <Context /> <!-- 现在常常使用自动部署,不推荐配置Context元素,Context小节有详细说明 --> </Host> </Engine> </Service> </Server> ``` 其中,`<Server>` 是顶层元素,代表整个 Tomcat 服务器;`<Service>` 元素将 `<Connector>` 和 `<Engine>` 关联起来;`<Connector>` 负责接收客户端请求并将其转发给 `<Engine>`;`<Engine>` 是 Servlet 引擎,负责处理请求;`<Host>` 代表虚拟主机;`<Context>` 代表一个 Web 应用程序[^1]。 #### 重要组件配置 ##### 1. Listener server.xml 中可以配置多个监听器,用于在 Tomcat 启动和关闭时执行特定操作。例如: ```xml <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JasperListener" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> ``` 这些监听器分别用于记录版本信息、支持 APR(Apache Portable Runtime)、处理 JSP 编译、防止 JRE 内存泄漏、管理全局资源生命周期和防止线程局部变量泄漏等[^4]。 ##### 2. Connector `<Connector>` 元素用于配置 Tomcat 服务器监听的端口和协议。常见配置如下: ```xml <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8"/> ``` - `port`:指定服务器监听的端口号。 - `protocol`:指定使用的协议,通常为 `HTTP/1.1`。 - `connectionTimeout`:指定连接超时时间(毫秒)。 - `redirectPort`:指定当需要安全连接时重定向的端口号。 - `URIEncoding`:指定请求 URI 的编码格式,通常设置为 `UTF-8` 以支持中文等特殊字符[^1]。 ##### 3. Engine `<Engine>` 元素代表 Servlet 引擎,负责处理请求。常见配置如下: ```xml <Engine name="Catalina" defaultHost="localhost"> <!-- 子元素 Host --> </Engine> ``` - `name`:指定引擎的名称。 - `defaultHost`:指定默认的虚拟主机。 ##### 4. Host `<Host>` 元素代表虚拟主机,用于将不同的域名或 IP 地址映射到不同的 Web 应用程序。常见配置如下: ```xml <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <!-- 子元素 Context --> </Host> ``` - `name`:指定虚拟主机的名称。 - `appBase`:指定 Web 应用程序的部署目录。 - `unpackWARs`:指定是否自动解压 WAR 文件。 - `autoDeploy`:指定是否自动部署新的 Web 应用程序。 ##### 5. Context `<Context>` 元素代表一个 Web 应用程序。虽然现在常常使用自动部署,不推荐在 server.xml 中手动配置 `<Context>` 元素,但了解其配置也是有必要的。常见配置如下: ```xml <Context path="/shopping" docBase="shopping" reloadable="true"/> ``` - `path`:指定 Web 应用程序的上下文路径。 - `docBase`:指定 Web 应用程序的部署目录。 - `reloadable`:指定是否在类文件发生变化时自动重新加载应用程序。 ### 优化建议 #### 1. 调整连接属性 可以通过调整 `<Connector>` 元素的 `maxThreads`、`minSpareThreads` 和 `maxConnections` 等属性来优化服务器的性能。例如: ```xml <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" maxThreads="200" minSpareThreads="25" maxConnections="1000"/> ``` - `maxThreads`:指定最大线程数,即同时处理的最大请求数。 - `minSpareThreads`:指定最小空闲线程数,即服务器启动时创建的初始线程数。 - `maxConnections`:指定最大连接数,即服务器同时处理的最大连接数。 #### 2. 关闭不必要的监听器 如果某些监听器在当前环境中不需要,可以将其从 server.xml 中移除,以减少服务器的启动时间和内存占用。 #### 3. 禁用自动部署 在生产环境中,建议将 `<Host>` 元素的 `autoDeploy` 属性设置为 `false`,以避免自动部署新的 Web 应用程序带来的安全风险和性能问题。 #### 4. 配置错误页面 可以在 `<Engine>` 或 `<Host>` 元素中配置错误页面,以便在出现错误时给用户提供更友好的提示。例如: ```xml <ErrorPage errorCode="404" location="/404.html"/> <ErrorPage errorCode="500" location="/500.html"/> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

XdpCs

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值