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

本文解析了如何使用C语言指针实现输入的两个整数a和b的比较,并按先大后小的顺序输出。通过指针操作演示了如何高效地完成任务。

问题 A: C语言10.1

题目描述

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

输入

两个用空格隔开的整数a和b。

输出

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

样例输入

5 9

样例输出

9 5
#include <stdio.h>


int main(void) {
    int a, b;
    int *p = &a, *q = &b;
    scanf("%d%d", &a, &b);
    printf("%d %d", *p > *q ? *p : *q, *p > *q ? *q : *p);
    return 0;
}

C语言-光伏MPPT算法:电导增量法扰动观察法+自动全局搜索Plecs最大功率跟踪算法仿真内容概要:本文档主要介绍了一种基于C语言实现的光伏最大功率点跟踪(MPPT)算法,结合电导增量法与扰动观察法,并引入自动全局搜索策略,利用Plecs仿真工具对算法进行建模与仿真验证。文档重点阐述了两种经典MPPT算法的原理、优缺点及其在不同光照和温度条件下的动态响应特性,同时提出一种改进的复合控制策略以提升系统在复杂环境下的跟踪精度与稳定性。通过仿真结果对比分析,验证了所提方法在快速性和准确性方面的优势,适用于光伏发电系统的高效能量转换控制。; 适合人群:具备一定C语言编程基础和电力电子知识背景,从事光伏系统开发、嵌入式控制或新能源技术研发的工程师及高校研究人员;工作年限1-3年的初级至中级研发人员尤为适合。; 使用场景及目标:①掌握电导增量法与扰动观察法在实际光伏系统中的实现机制与切换逻辑;②学习如何在Plecs中搭建MPPT控制系统仿真模型;③实现自动全局搜索以避免传统算法陷入局部峰值问题,提升复杂工况下的最大功率追踪效率;④为光伏逆变器或太阳能充电控制器的算法开发提供技术参考与实现范例。; 阅读建议:建议读者结合文中提供的C语言算法逻辑与Plecs仿真模型同步学习,重点关注算法判断条件、步长调节策略及仿真参数设置。在理解基本原理的基础上,可通过修改光照强度、温度变化曲线等外部扰动因素,进一步测试算法鲁棒性,并尝试将其移植到实际嵌入式平台进行实验验证。
<?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、付费专栏及课程。

余额充值