Kylin

Kylin
8天前

https://www.luogu.com.cn/paste/yo55yexq

#include[HTML_REMOVED]
using namespace std;
const int maxn = 10500;
int A[maxn], B[maxn], ans[maxn];
string a, b;
int num;

void pd()
{
if(a.size() < b.size() || (a.size() == b.size() && a < b))
{
cout << “-“;
swap(a, b);
}
}

int main()
{
cin >> a >> b;
pd();
for(int i = 0; i < a.size(); i )
A[a.size() - i - 1] = (a[i] - ‘0’);
for(int i = 0; i < b.size(); i
)
B[b.size() - i - 1] = (b[i] - ‘0’);
for(int i = 0; i < a.size(); i ++)
{
if(A[i] < B[i])
{
A[i + 1] –;
A[i] += 10;
}
ans[i] = A[i] - B[i];
}
num = a.size()-1;
while(!ans[num]) num–;
if(num == 0 && ans[num] == 0)
cout << “0”;
else {
for(int i = num; i >= 0; i –)
cout << ans[i];
}
return 0;

}

Kylin
11天前

https://www.luogu.com.cn/paste/2d3wnruk

Kylin
1个月前

#include[HTML_REMOVED]
using namespace std;
const int maxn = 1e6+10;
int n, q[maxn];

void quick_sort(int q[], int l, int r)
{
if(l >= r) return;
int x = q[l], i = l - 1, j = r + 1;
while(i < j)
{
do i++; while(q[i] < x);
do j–; while(q[j] > x);
if(i < j) swap(q[i], q[j]);
}
quick_sort(q, l, j);
quick_sort(q, j+1, r);
}

int main()
{
scanf(“%d”, &n);
for(int i = 0; i < n; i)
scanf(“%d”, &q[i]);
quick_sort(q, 0, n-1);
for(int i = 0; i < n; i
)
printf(“%d “, q[i]);
return 0;
}

Kylin
3个月前
//这里填你的代码^^
class Solution {
public:
int maxVowels(string s, int k) {
unordered_set<char> S({'a','e','i','o','u'});
int res=0;
for(int i=0,cnt=0;i<s.size();i++){
cnt+=S.count(s[i]);
if(i>=k) cnt-=S.count(s[i-k]);
if(i>=k-1) res=max(res,cnt);
}
return res;
}
};
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


Kylin
3个月前
//这里填你的代码^^
class Solution {
public:
int isPrefixOfWord(string sentence, string searchWord) {
stringstream ssm(sentence);
string word;
for(int i=1;ssm>>word;i++){
if(word.substr(0,searchWord.size())==searchWord)
return i;
}
return -1;
}
};
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


Kylin
4个月前
//这里填你的代码^^
/**
* Definition for a binary tree node.
* struct TreeNode {
*     int val;
*     TreeNode *left;
*     TreeNode *right;
*     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int>> ans;
vector<vector<int>> findPath(TreeNode* root, int sum) {
vector<int> path;
dfs(root,sum,path);
return ans;
}
void dfs(TreeNode* root, int sum,vector<int>path){
if(!root) return;
path.push_back(root->val);
sum-=root->val;
if(!root->left&&!root->right&&!sum) ans.push_back(path);
dfs(root->left,sum,path);
dfs(root->right,sum,path);
path.pop_back();
sum+=root->val;
}
};
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


Kylin
4个月前
//这里填你的代码^^
class Solution {
public:
vector<int> seq;
bool verifySequenceOfBST(vector<int> sequence) {
seq=sequence;
if(seq.empty()) return true;
return dfs(0,seq.size()-1);
}
bool dfs(int l,int r){
int k,root;
root=seq[r];
while(k<r&&seq[k]<root) k++;
for(int i=k;i<r;i++) if(seq[i]<root) return false;
if(l>=r) return true;
return dfs(l,k-1)&&dfs(k,r-1);
}
};
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


Kylin
4个月前
//这里填你的代码^^
class Solution {
public:
while(p&&q)
{
p=p->next;
q=q->next;
if(q) q=q->next;
else return 0;
if(p==q)
{
while(p!=q){
p=p->next;
q=q->next;
}
return p;
}
}
return 0;
}
};
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


Kylin
4个月前
//这里填你的代码^^
class MinStack {
public:
/** initialize your data structure here. */
stack<int> stackValue;
stack<int> stackMin;
MinStack() {

}

void push(int x) {
stackValue.push(x);
if (stackMin.empty() || stackMin.top() >= x)
stackMin.push(x);
}

void pop() {
if (stackMin.top() == stackValue.top()) stackMin.pop();
stackValue.pop();
}

int top() {
return stackValue.top();
}

int getMin() {
return stackMin.top();
}
};

//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


Kylin
4个月前
//这里填你的代码^^
class Solution {
public:
vector<int> printMatrix(vector<vector<int>>& matrix) {
vector<int> res;
if (matrix.empty()) return res;
int n = matrix.size(), m = matrix[0].size();
vector<vector<bool>> st(n, vector<bool>(m, false));
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
int x = 0, y = 0, d = 1;
for (int k = 0; k < n * m; k ++ )
{
res.push_back(matrix[x][y]);
st[x][y] = true;

int a = x + dx[d], b = y + dy[d];
if (a < 0 || a >= n || b < 0 || b >= m || st[a][b])
{
d = (d + 1) % 4;
a = x + dx[d], b = y + dy[d];
}
x = a, y = b;
}
return res;
}
};

//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~