算法day06

本文介绍了一个关于TEX排版系统中正确使用引号的问题——POJ1488 TEXQuotes。文章详细解释了如何将普通双引号转换为TEX所需的左引号和右引号,并提供了一段C++代码实现这一转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. POJ 1488
TEX Quotes
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 9046 Accepted: 4743

Description
TEX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use double-left-quote and double-right-quote to delimit quotations, rather than the mundane ” which is what is provided by most keyboards. Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote and a right-single-quote '. Check your keyboard now to locate the left-single-quote key (sometimes called the “backquote key”) and the right-single-quote key ’ (sometimes called the “apostrophe” or just “quote”). Be careful not to confuse the left-single-quote ` with the “backslash” key . TEX lets the user type two left-single-quotes “ to create a left-double-quote and two right-single-quotes ” to create a right-double-quote. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote “.

If the source contained
“To be or not to be,” quoth the bard, “that is the question.”
then the typeset document produced by TEX would not contain the desired form: “To be or not to be,” quoth the bard, “that is the question.” In order to produce the desired form, the source file must contain the sequence:
To be or not to be,'' quoth the bard,that is the question.”
You are to write a program which converts text containing double-quote (“) characters into text that is identical except that double-quotes have been replaced by the two-character sequences required by TEX for delimiting quotations with oriented double-quotes. The double-quote (“) characters should be replaced appropriately by either if the " opens a quotation and by '' if the " closes a quotation. Notice that the question of nested quotations does not arise: The first " must be replaced by, the next by ”, the next by , the next by '', the next by, the next by ”, and so on.

Input
Input will consist of several lines of text containing an even number of double-quote (“) characters. Input is ended with an end-of-file character.

Output
The text must be output exactly as it was input except that:

the first " in each pair is replaced by two ` characters: `` and 
the second " in each pair is replaced by two ' characters: ''. 

Sample Input

“To be or not to be,” quoth the Bard, “that
is the question”.
The programming contestant replied: “I must disagree.
To C' or not toC’, that is The Question!”

Sample Output

To be or not to be,'' quoth the Bard,that
is the question”.
The programming contestant replied: `I must disagree.
To
C’ or not to `C’, that is The Question!”

代码:

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const char p[][5] = {"``","''"};//p[0]为两个“·”字符,p[1]为两个“‘”
int main()
{
    int k=0;
    char c;
    while ((c=getchar())!=EOF)
    {
        if(c=='"')
        {
            printf("%s",p[k]);
            k=!k;
        }
        else
            putchar(c);
    }
    return 0;
}
### 苍穹外卖 Day06 `list` 报错 401 的原因分析 在苍穹外卖项目的第六天教学内容中,当调用 `list` 方法时遇到 HTTP 状态码 401 错误的情况,通常是因为 JWT 验证失败所致。以下是具体的原因分析以及解决方案: #### 原因一:JWT Token 不匹配 如果调试过程中发现设置的 JWT Token 和解析的 JWT Token 不一致,则可能是由于混淆了管理员 (`admin`) 和用户 (`user`) 的密钥 (Secret Key)[^1]。此时应检查以下两点: - **Token 设置阶段**:确认生成 Token 使用的 Secret Key 是否正确。 - **Token 解析阶段**:确保解析 Token 所使用的 Secret Key 与生成时保持一致。 #### 原因二:拦截器配置错误 另一个常见原因是未正确配置拦截器,导致某些请求被不必要地放行或阻拦[^1]。例如,在开发环境中为了快速定位问题而临时关闭拦截器的行为可能导致后续逻辑混乱。因此建议恢复默认拦截规则并重新测试。 #### 关于 `list` 方法的具体实现 根据引用中的代码片段可以推测出 `list` 方法的功能是从数据库获取指定分类下的套餐列表数据[^3]。其核心逻辑如下所示: ```java @Override public List<Setmeal> list(Setmeal setmeal) { // 调用 Mapper 层方法按条件查询符合条件的所有套餐记录 List<Setmeal> list = setmealMapper.getByCategoryId(setmeal); return list; } ``` 此段代码展示了如何通过传入参数对象来筛选特定类别下的所有可用套餐信息,并返回给前端展示使用。 #### 如何解决 401 问题? 针对以上提到的各种可能性逐一排查即可解决问题: 1. 检查服务端是否正常接收到了客户端发送过来的有效认证凭证; 2. 如果确实存在 token 参数缺失或者格式非法等问题则需修正相应接口文档说明以便开发者遵循标准流程操作; 3. 对比前后两端所采用的安全加密算法版本号及其对应私钥文件是否存在差异情况;最后再利用工具软件模拟真实场景下发起网络请求动作从而进一步验证修复效果。 --- ### 示例代码:校验 JWT 工具类 下面提供了一个简单的用于检验输入字符串是否合法有效的辅助函数作为参考: ```java @Service @Slf4j public class JwtUtil { private static final String SECRET_KEY_ADMIN = "your_admin_secret_key"; private static final String SECRET_KEY_USER = "your_user_secret_key"; /** * Validates the given jwt token. * * @param token The jwt token to validate. * @return true if valid, false otherwise. */ public boolean isValid(String token, UserType userType) { try { Algorithm algorithm = Algorithm.HMAC256(getSecretKey(userType)); JWTVerifier verifier = JWT.require(algorithm).build(); DecodedJWT decodedJwt = verifier.verify(token); log.info("Decoded JWT claims: {}", decodedJwt.getClaims()); return true; } catch (Exception e) { log.error("Invalid JWT token", e); return false; } } private String getSecretKey(UserType userType){ switch (userType){ case ADMIN : return SECRET_KEY_ADMIN ; default : return SECRET_KEY_USER ; } } } // Enum representing user types enum UserType{ USER, ADMIN } ``` 上述代码定义了一个名为 `isValid()` 的静态成员函数用来判断任意形式化表达式的布尔值状态。它接受两个参数分别是待检测的目标串以及当前登录者的身份角色标识符。内部实现了基于 HMAC-SHA256 加密方式的身份鉴别机制并通过捕获异常的方式处理潜在风险因素。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值