太戈编程 2题

目录

2. 删除最大和最小

题目描述

输入格式

输出格式

代码:


2. 删除最大和最小

题目描述

        请写一个程序,输入n个不同的整数,删除最大数字和最小数字,依次输出剩余n-2个整数。

输入格式

输入共两行:第一行为正整数n,第二行为n个整数。
其中n<=100,数字绝对值不超过100000。

输出格式

一行共n-2个整数

代码

#include<iostream>
using namespace std;
const int N=109;
int n,f[N];
int main(){	
	cin>>n;
	for(int i=0;i<n;i++) cin>>f[i];
	int big=f[0];
	for(int i=1;i<n;i++){
		if(f[i]>big){
			big=f[i];
		}
	}
	int small=f[0];
	for(int i=1;i<n;i++){
		if(f[i]<small){
			small=f[i];
		}
	}
	for(int i=0;i<n;i++){
		if(f[i]!=big&&f[i]!=small){
			cout<<f[i]<<" ";
		}
	}
	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的具体要求可能会有所不同,因此建议查阅具体课程资料或联系导师获得最准确的帮助。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值