Deque
À mình hiểu rồi, thật ra cách làm của bạn không cần dùng đến Deque và hơn nữa nó thực chất là kĩ thuật trượt cửa sổ 😉
Sắp xếp ba số
Code 'Lua':
a = tonumber(io.read())
b = tonumber(io.read())
c = tonumber(io.read())
if a > b then a, b = b, a end
if a > c then a, c = c, a end
if b > c then b, c = c, b end
print(a, b, c)
Cánh Diều - REPLACE - Thay thế
Code ngôn ngữ 'lua'
q = tonumber(io.read())
for i = 1, q do
y = io.read()
a = io.read()
b = io.read()
pat = a:gsub("(%W)", "%%%1")
res = y:gsub(pat, b)
print(res)
end
Tính tổng
include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
long long ssh = ((n - 1) / 1)+ 1;
long long s = ((1 + n) * ssh) / 2;
cout << s;
}
Tính tổng
include <iostream>
using namespace std;
int main() {
long long n;
cin >> n;
long long ssh = ((n - 1) / 1)+ 1;
long long s = ((1 + n) * ssh) / 2;
cout << s;
}
Tìm số (THTA Lâm Đồng 2022)
Tại sao sai vậy mọi người
Code mẫu WA (70.0/100 điểm)
n = int(input())
if n % 10 > 0 and n % 10 < 6:
print (n * 2 - 1)
else:
print (n * 2 - 2)
KNTT10 - Trang 126 - Luyện tập 1
C++ AC ( •̀ ω •́ )✧
// C++ mẫu lập trình thi đấu
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<string>split(string str, char removeChar = ' '){
string subStr = "";str+=removeChar;
vector<string> strSplited;
for(char&x : str){
if(x == removeChar && subStr != "")strSplited.push_back(subStr), subStr.clear();
else subStr+=x;
}
return strSplited;
}
double str_Double(string str){
double num = 0;
for(ll i = 0;i < str.size();i++){
if(str[i] == '.'){
double phanThapPhan = 0.0;
for(ll j = str.size()-1;j > i;j--){
phanThapPhan+=str[j]-48;
phanThapPhan*=0.1;
}
num+=phanThapPhan;break;
}
num = num*10 + (str[i]-48);
}
return num;
}
vector<double>strVT_DoubleVT(vector<string>strs){
vector<double>nums;
for(string&x : strs){
nums.push_back(str_Double(x));
}
return nums;
}
double sum(vector<double> nums){
double result = 0;
for(double&x : nums)result+=x;
return result;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
string nums;getline(cin, nums);
cout << sum(strVT_DoubleVT(split(nums)));
return 0;
}
CSES - Maximum Xor Subarray | Đoạn con có xor lớn nhất
Hint
2 số xor max khi là đảo bit của nhau => duyệt bit từ trái qua phải ưu tiên chọn số có bit đối với bit hiện tại
Hint
f[i] = a[1]^a[2]^..^a[i]
=> kq = max(f[i]^f[j])
Report
bé này chép code chatgpt nekk, link : file:///C:/Users/pc/Desktop/%E1%BA%A3nh/%E1%BA%A3nh%202/Capture.PNG