太戈编程 7题

7. 大小写转换

题目描述

将字符串中的大写字母转为小写,小写字母转为大写

输入格式

一行字符串,只包含字母,无需检查输入合法性

输出格式

一行字符串

代码

#include<bits/stdc++.h>
using namespace std;
char c;
int main(){
    while(cin>>c){
        if(c>='A'&&c<='Z')cout<<char(c+32);
        if(c>='a'&&c<='z')cout<<char(c-32);
    }
    return 0;
}

针对编程第298答案,虽然无法直接获取该特定目确切的内容和官方解答[^1],可以提供一个假设性的解决方案框架基于常见的编程教育平台习模式。 ### 假设性问描述 假定此目涉及创建一个类结构用于表示不同类型的诗歌以及实现猜诗歌的小游戏功能。这可能涉及到面向对象的概念如继承、多态等特性。 #### 创建基础诗歌类 ```python class Poem: def __init__(self, title, author, dynasty, content): self.title = title self.author = author self.dynasty = dynasty self.content = content def display_info(self): print(f"Title: {self.title}") print(f"Author: {self.author}") print(f"Dynasty: {self.dynasty}") def guess_dynasty(self, user_guess): return user_guess.lower() == self.dynasty.lower() ``` #### 扩展子类支持更多互动方式 为了增加趣味性和挑战度,可以从`Poem`派生出新的类来处理不同的猜测形式: ```python from random import choice class GuessNextLine(Poem): def get_next_line_options(self): lines = self.content.splitlines() line_index = choice(range(len(lines)-1)) options = [ lines[line_index + 1], # 正确答案 *choice([line for i,line in enumerate(lines) if i != (line_index+1)], size=3) # 错误选项 ] return line_index, lines[line_index], options def play_game(self): idx, current_line, next_lines = self.get_next_line_options() print(f"The given line is:\n{current_line}\n") correct_answer = None while True: for index, option in enumerate(next_lines): print(f"{index}: {option}") try: answer_idx = int(input("Please enter the number of your chosen option: ")) selected_option = next_lines[answer_idx] if selected_option.strip().lower() == next_lines[0].strip().lower(): print("Correct!") break else: print("Incorrect! Try again.") except ValueError as e: print("Invalid input. Please provide a valid integer.") ``` 上述代码展示了如何构建基本的诗歌类及其扩展版本以适应更复杂的交互需求。然而请注意实际的编程第298的具体要求可能会有所不同,因此建议查阅具体课程资料或联系导师获得最准确的帮助。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值