UVa 10055 - Hashmat the Brave Warrior

时间限制:3秒


Hashmat 是个勇敢的战士,带着一票年轻的战士们跑去打仗。然后打仗之前他要先对比一下自己人数比对面人数差多少,然后决定打不打(Hashmat 的人数始终比对面少)……

真是勇敢的战士……嗯……



输入是一行两个数,分别是Hashmat 的人数和对面的人数,或者反过来。人数不大于2^32,输入读到EOF结束。

输出两边人数差多少。


其实就是输入两个数输出差的绝对值。

注意的地方其实就两个:

一个小坑是两个数谁大谁小不确定,虽然原文里Hashmat 的人数一定小于对面,但是输入次序不一定是Hashmat在前。

另一个坑是数据不大于2^32,也就是说可能等于2^32,超出了int的上限。


当年刷UVa的一血就这个……


#include <iostream>

using std::cin;
using std::cout;
using std::endl;

int main() {
    unsigned long long a, b;
    while(cin >> a >> b) {
        cout << (a > b ? a - b : b - a) << endl;
    }
    return 0;
}


哎哎!?

好像UVa可以交Python3的代码了欸,甚好,甚好……

顺手写了个Python3版本的,不过这个EOF好像略烦啊……不知道这么写是不是标准做法……

while True:
    try:
        line = input()
    except EOFError:
        break
    data = [int(i) for i in line.split()]
    a = data[0]
    b = data[1]
    print(abs(a - b))


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
我理解你的问题是关于在Spring Boot 3中使用Micrometer Tracing Bridge Brave进行RabbitMQ链路追踪时遇到的问题。 首先,你需要在你的项目中添加以下依赖: ```xml <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-core</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-zipkin</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-tracing-bridge-brave</artifactId> </dependency> ``` 然后,在你的配置文件中,你需要启用Micrometer和Zipkin: ``` management.metrics.export.zipkin.enabled=true management.metrics.export.zipkin.uri=http://localhost:9411 ``` 接下来,你需要配置RabbitMQ,以便将跟踪信息添加到消息头中: ``` @Bean public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory, Tracer tracer) { RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory); rabbitTemplate.setBeforePublishPostProcessors(message -> { Span span = tracer.currentSpan(); if (span != null) { message.getMessageProperties().setHeader("X-B3-TraceId", span.context().traceIdString()); message.getMessageProperties().setHeader("X-B3-SpanId", span.context().spanIdString()); } return message; }); return rabbitTemplate; } ``` 最后,你需要在你的应用程序中创建一个跨度: ```java @Autowired private Tracer tracer; public void sendMessage() { Span span = tracer.nextSpan().name("sendMessage").start(); try (Tracer.SpanInScope ws = tracer.withSpan(span)) { // 发送消息 } finally { span.finish(); } } ``` 如果你的链路追踪仍然无效,可能是因为你的RabbitMQ配置不正确或你的Zipkin服务器没有启动。你可以使用Zipkin UI查看跟踪信息,或者使用Zipkin API查询跟踪信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值