zir

sdu

75

zir
5天前
class Solution {
public:
vector<int> printListReversingly(ListNode* head) {
vector<int> r;
}
reverse(r.begin(),r.end());
return r;
}
};


zir
5天前
        int i = 0,j = 0;
for(;j<str.length();j++){
if(str[j] == ' '){
s[i++] = '%',s[i++] = '2',s[i++] = '0';
}else s[i++] = str[j];
}
string res(s);
return res;


zir
5天前
        //剔除空矩阵
if(array.empty()||array[0].empty())return false;
int i = 0, j = array[0].size()-1;
while(i<array.size()&&j>=0){
int x = array[i][j];
if(x == target)return true;
if(x>target)j--;
else i++;
}
return false;


zir
10天前

### 代码

#include <iostream>
#include <cstring>

using namespace std;
int n;
const int N = 207003;
int h[N],e[N],ne[N],idx;

bool find(int x){
int t = (x%N+N)%N;
//~i等价于i!=-1
for(int i = h[t];~i;i=ne[i])if(e[i]==x)return true;
return false;
}

//拉链法
void insert(int x){
if(find(x))return;
int t = (x%N+N)%N;
e[idx] = x,ne[idx] = h[t],h[t] = idx++;
}

int main(){
memset(h,-1,sizeof(h));
int n,num;
char cm[2];
cin>>n;
for(int i=0;i<n;i++){
scanf("%s%d",cm,&num);
if(*cm=='Q'){
if(find(num))printf("Yes\n");
else printf("No\n");
}else insert(num);
}
}


zir
22天前

### 题目描述

#### 样例

#include <iostream>
using namespace std;
const int N = 10;
bool use[N];
int n, path[N];

void dfs(int x){
if(x>n){
for(int i = 1;i<=n;i++)cout<<path[i]<<" ";
cout<<endl;
}
else{
for(int i = 1;i<=n;i++){
if(!use[i]){
use[i] = true;
path[x] = i;
dfs(x+1);
use[i] = false;
}
}

}

}

int main(){
cin>>n;
dfs(1);
}



zir
1个月前
#include <iostream>
using namespace std;
const int N = 100010;
int son[N][26], idx = 0, cnt[N];

void insert(char *str){
int t = 0;
for(int i = 0;str[i];i++){
int u = str[i] - 'a';
if(!son[t][u])son[t][u] = ++idx;
t = son[t][u];
}
cnt[t]++;
}

int query(char *str){
int t = 0;
for(int i = 0;str[i];i++){
int u = str[i] - 'a';
if(!son[t][u])return 0;
t = son[t][u];
}
return cnt[t];
}

int main(){
int n;
scanf("%d",&n);
while(n--){
char op[2],str[100010];
scanf("%s%s",op,str);
if(op[0]=='I')insert(str);
else if(op[0]=='Q')printf("%d",query(str));
}
}
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


zir
1个月前
//这里填你的代码^^
#include <iostream>
using namespace std;

const int N = 100010;
int a[N],b[N];

int main(){
int n,m,x;
cin>>n>>m>>x;
for(int i = 0;i<n;i++)cin>>a[i];
for(int i = 0;i<m;i++)cin>>b[i];
int i = 0, j = m-1;
for(;i<n;i++){
while(a[i] + b[j] > x)j--;
if(a[i]+b[j] == x)break;
}
printf("%d %d", i,j);
}
//注意代码要放在两组三个点之间，才可以正确显示代码高亮哦~


zir
1个月前
#include <iostream>
using namespace std;

const int N = 100010;
int a[N];

int main(){
int n;
cin>>n;
for(int i = 0;i<n;i++)cin>>a[i];
for(int i = 0;i<n;i++){
int x = a[i], num = 0;
while(x){
int k = x&(x*-1);
num++;
x -= k;
}
cout<<num<<" ";
}
}


zir
1个月前
#include <iostream>
using namespace std;

const int N = 100010;
int a[N];

int main(){
int n;
cin>>n;
for(int i = 0;i<n;i++)cin>>a[i];
for(int i = 0;i<n;i++){
int x = a[i], num = 0;
while(x){
int k = x&(x*-1);
num++;
x -= k;
}
cout<<num<<" ";
}
}


zir
2个月前
#include <iostream>
#include <cstring>
using namespace std;

const int N = 100010;
int a[N], table[N];

int main(){
int n,res = 0;
cin>>n;
for(int i = 0;i<n;i++)cin>>a[i];
for(int i = 0,j = 0;i<n;i++){
table[a[i]]++;
while(table[a[i]]>1)table[a[j++]]--;
res = max(res,i-j+1);
}
cout<<res;
}