山东第7届省赛 K题 Reversed Words

本文介绍了一道有趣的编程题——翻译一种特殊的外星语言。这种语言的特点是将每个单词反转,但句子中单词的顺序不变。文章提供了示例输入输出,并附带了解题的示例代码。

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



Reversed Words

Time Limit: 2000MS Memory limit: 131072K

题目描述

Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.

Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!

输入

 Multiple test cases. The first line contains a positive integer T (T <= 1000), indicating the number of test cases.

For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.

输出

 One line per case, the translated sentence.

示例输入

2
eno owt eerht
abcde

示例输出

one two three
edcba

提示

 

来源

  “浪潮杯”山东省第七届ACM大学生程序设计竞赛

示例程序

 把字符串中的单词反向输出
ACcode:
#include <bits/stdc++.h>
#define maxn 10100
using namespace std;
char dp[maxn];
int main(){
    int n,loop,cnt=1;
    scanf("%d",&loop);
    getchar();
    while(loop--){
        gets(dp);
        int pos=0,len=strlen(dp);
        for(int i=0;i<len;){
            if(dp[i]==' '){
                for(int j=i-1;j>=pos;--j)putchar(dp[j]);
                putchar(' ');
                while(dp[i]==' '&&i<=len)i++;
                pos=i;
            }
            else if(dp[i+1]=='\0'){
                for(int j=i;j>=pos;--j)putchar(dp[j]);
                putchar('\n');
                break;
            }
            else i++;
        }
    }
    return 0;
}


Reversed Words

Time Limit: 2000MS Memory limit: 131072K

题目描述

Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.

Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!

输入

 Multiple test cases. The first line contains a positive integer T (T <= 1000), indicating the number of test cases.

For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.

输出

 One line per case, the translated sentence.

示例输入

2
eno owt eerht
abcde

示例输出

one two three
edcba

提示

 

来源

  “浪潮杯”山东省第七届ACM大学生程序设计竞赛

示例程序

 
### 蓝桥杯第15解析 #### 一、概述 蓝桥杯大是一项面向全国高校学生的IT类竞活动,旨在推动软件开发技术的发展以及培养高水平的信息技术人才。其中,第15涵盖了多种类型的目,涉及Python编程、C/C++编程、单片机应用等多个领域[^2]。 #### 二、具体目解析 ##### Python 编程部分 在青少年组的比中,有一道关于整数逆序输出的经典目。该要求参者编写一段代码实现输入的一串数字按逆序排列后输出的功能。以下是基于此需求的一种解决方案: ```python def reverse_integer(n): reversed_str = str(abs(n))[::-1] result = int(reversed_str) if n < 0: result *= -1 return result n = int(input()) print(reverse_integer(n)) ``` 上述代码首先将输入的整数转成字符串形式以便于操作其字符序列,之后再反转字符串并重新组合为整型数值。如果原始输入是一个负数,则需特别注意恢复其符号属性[^1]。 ##### 单片机控制逻辑设计 针对嵌入式系统的挑战,在某项任务中涉及到温湿度传感器的数据读取与LED状态更新机制的设计思路如下所示: 为了确保只有当新的测量值确实高于前一次记录时才触发相应动作(比如点亮某个特定颜色的灯泡),可以在主循环内部加入额外判定条件来验证当前周期内的采样结果是否满足预设阈值约束[Tick>0] 和 [Tick>=2][^3]。 ```c if (currentTemp > lastTemp && currentHumidity > lastHumidity && Tick >=2){ LED_ON(); } else{ LED_OFF(); } delay_ms(DELAY_TIME); lastTemp=currentTemp; lastHumidity=currentHumidity; ``` 此处`Tick`计时器的作用是用来规避初始阶段可能存在的误判情况;而延迟函数则有助于稳定整个流程节奏,避免过于频繁的操作影响硬件寿命或者造成视觉干扰现象发生。 ##### 数据结构运用实例——Map 方法实践 对于更高级别的选手来说,掌握一些常见的数据处理技巧是非常必要的。下面展示了一个有关目录遍历生成树形结构的例子,它巧妙地利用到了 JavaScript 中 Array 的 `map()` 函数特性来进行递归式的子节点构建过程[^4]: ```javascript function generateTree(dirPath) { const items = fs.readdirSync(dirPath); return items.map((item)=>{ const itemPath = path.join(dirPath, item); if(fs.statSync(itemPath).isDirectory()){ return {name:item, children:generateTree(itemPath)}; } else{ return {name:item}; } }); } const treeStructure = generateTree('/example/path'); console.log(JSON.stringify(treeStructure)); ``` 这段脚本能够自动探索指定路径下的所有文件夹及其包含的内容,并以易于理解的形式呈现出来供后续进一步分析使用。 --- #### 总结 以上仅列举了几种典型的蓝桥杯第十五可能出现的技术考察方向及相关解答示范。实际比过程中还会有更多复杂度更高的命等待着各位参者的攻克! 相关问
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值