非大题在本地pdf中有详解
21.异或
#include <iostream>
using namespace std;
long long change(long long x){
if(x % 4 == 0){
return x;
}else if(x % 4 == 1){
return 1;
}else if(x % 4 == 2){
return x + 1;
}else if(x % 4 == 3){
return 0;
}else{
return 0;
}
}
int main() {
long long a, b;
while (cin >> a >> b) { // 注意 while 处理多个 case
long long ans = change(a - 1) ^ change(b);
printf("%lld", ans);
}
}
// 64 位输出请用 printf("%lld")
22.小度的部队
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
int a, b;
while (cin >> a >> b) { // 注意 while 处理多个 case
stack<int> stk;
stk.push(a);
int ans = 0;
while(stk.size()){
int n = stk.top();
stk.pop();
if(n - b <= 0){
ans += 1;
}
else if((n - b) % 2 == 0){
// /2
int i = (n - b) / 2;
stk.push(i);
stk.push(i + b);
}else if((n - b) % 2){
ans += 1;
}
}
cout << ans;
}
}
// 64 位输出请用 printf("%lld")
23.设置标签
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.tag-input{
position: relative;
border: 1px solid #cccccc;
padding: 0 5px;
display: flex;
flex-flow: row wrap;
}
.js-input{
width: 450px;
height: 22px;
line-height: 22px;
font-size: 16px;
padding: 0;
margin: 5px 0;
outline: none;
border: none;
width: 6.5em;
height: 24px;
line-height: 24px;
}
.tag{
padding: 0 10px;
margin: 5px 5px 5px 0;
background: #25bb9b;
color: #ffffff;
height: 24px;
line-height: 24px;
border-radius: 12px;
font-size: 13px;
}
</style>
</head>
<body>
<div class="tag-input">
<span class="tag">前端</span>
<span class="tag">编程题</span>
<span class="tag">示例</span>
<span class="tag">标签</span>
<input type="text" class="js-input" maxlength="6" placeholder="请输入标签" value="123">
</div>
<script type="text/javascript">
var tagInput = {
isInited: false,
init: init,
bindEvent: bindEvent,
addTag: addTag,
removeTag: removeTag
};
tagInput.init();
function init() {
var that = this;
if (that.isInited) return;
that.isInited = true;
// 请修改这一行代码,保存class为js-input的输入框的dom元素引用
// var a = document.getElementsByClassName("js-input")[0];
// console.log("@@@",a);
that.input = document.getElementsByClassName("js-input")[0];
// that.input = document.querySelector('.js-input');
that.bindEvent();
}
function bindEvent() {
var that = this;
var input = that.input;
if (!input) return;
input.addEventListener('keydown', function (event) {
// 请修改这一行代码,判断用户是否按了回车键
var isEnter = event.keyCode === 13;
// 请修改这一行代码,判断用户是否按了删除键
var isDelete = event.keyCode === 8 && !that.input.value.trim();
(isEnter || isDelete) && event.preventDefault();
isEnter && that.addTag();
isDelete && that.removeTag();
});
input.parentNode.addEventListener('click', function () {
input.focus();
});
}
function addTag() {
// 1、当用户输入内容并敲回车键时,将输入框的内容在输入框前显示成标签,并清空输入框内容
var that = this;
// 3、标签需要去掉字符串两端的多余的空格
var value = that.input.value.trim();
// console.log('@@@@',that);
// console.log('11@@',value);
// 4、标签不能为空字符串
if (!value) return;
// 并清空输入框内容
that.input.value = '';
// 5、标签不能重复,如果输入已存在的内容相同的标签,则不添加,并清空输入框
// 判断是否已经存在
if (that.input.parentNode.innerText.includes(value)) return;
// 将输入框的内容在输入框前显示成标签
var tag = document.createElement('span');
tag.className = 'tag';
tag.innerText = value;
that.input.parentNode.insertBefore(tag, that.input);
}
function removeTag() {
// 2、当用户敲删除键时,如果输入框当前没有内容,则删除前一个标签
var that = this;
var preTag = that.input.previousElementSibling;
// console.log('@@@',that);
// 前一个标签存在才删除
preTag && preTag.remove();
}
</script>
</body>
</html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)