day17

该程序接收用户输入的三个整数数组,然后对数组进行排序。通过双指针法找到所有满足条件(i<j<k)且Ai<Bj<Ck的递增三元组,计算并输出其数量。
摘要由CSDN通过智能技术生成

1打卡题

  1. 递增三元组

package daka;

import java.util.*;

/*递增三元组

* 三个数组

* 三元组(i,j,k) 满足: 1<=i,j,k <=n;

* Ai<bj<ck;

* 111

* 222

* 333

* 27(9 * 3);

*/

public class dezeng {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int n = sc.nextInt();

int [] a = new int [n+1];

int [] b = new int [n+1];

int [] c = new int [n+1];

for(int i=1;i<=n;i++) {

int num = sc.nextInt();

num = a[i];

}

for(int i=1;i<=n;i++) {

int num = sc.nextInt();

num = b[i];

}

for(int i=1;i<=n;i++) {

int num = sc.nextInt();

num = c[i];

}

Arrays.sort(a);Arrays.sort(b);Arrays.sort(c);

long res = 0; //注意long类型。不用的话过不了

//指针在a和c数组中移动,同时固定b数组的指针遍历

//indexa:数组a中小于b的最后一个下标

//indexb:数组c中大于b的第一个下标

//a一定小于b且不等于b,c一定大于b,但可以等于b

for(int i =1, indexa = 1,indexc = 1;i<=n;i++) {

//indexa < i <= indexc

while(indexa<=n && a[indexa]< b[i]) {

indexa++;

}

while(indexc <=n && c[indexc]<= b[i]) {

indexc++;

}

res += (long)(indexa -1) * (n-indexc -1);

}

System.out.println(res);

}

}

3.你们

4.

Day17 中,我们可以通过 Flask 框架快速搭建一个 BBS 论坛。具体步骤如下: 1. 创建 Flask 应用 ```python from flask import Flask app = Flask(__name__) ``` 2. 创建数据库 ```python from flask_sqlalchemy import SQLAlchemy app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///bbs.db' app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db = SQLAlchemy(app) ``` 3. 创建数据库模型 ```python class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(20), unique=True, nullable=False) password = db.Column(db.String(20), nullable=False) class Post(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(100), nullable=False) content = db.Column(db.Text, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False) ``` 4. 创建路由和视图函数 ```python @app.route('/') def index(): posts = Post.query.all() return render_template('index.html', posts=posts) @app.route('/post/<int:post_id>') def post(post_id): post = Post.query.get(post_id) return render_template('post.html', post=post) @app.route('/new_post', methods=['GET', 'POST']) def new_post(): if request.method == 'POST': title = request.form['title'] content = request.form['content'] user_id = 1 # 假设当前用户为 id 为 1 的用户 post = Post(title=title, content=content, user_id=user_id) db.session.add(post) db.session.commit() return redirect('/') return render_template('new_post.html') @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] user = User.query.filter_by(username=username, password=password).first() if user: session['user_id'] = user.id return redirect('/') else: flash('用户名或密码错误') return render_template('login.html') @app.route('/logout') def logout(): session.pop('user_id', None) return redirect('/') ``` 5. 创建 HTML 模板 创建 index.html、post.html、new_post.html、login.html 四个模板文件,并且使用 jinja2 模板引擎渲染数据。 6. 运行应用 ```python if __name__ == '__main__': app.run() ``` 以上就是快速搭建 BBS 论坛的主要步骤,当然在实际应用中还需要考虑更多细节问题,比如用户认证、数据校验、页面美化等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

螺上螺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值