Skip to content

Commit ddd0d2a

Browse files
committed
biweekly 102
1 parent ece1901 commit ddd0d2a

4 files changed

+185
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
#include <bits/stdc++.h>
6+
using namespace std;
7+
typedef long long ll;
8+
9+
10+
int solve(){
11+
string s;
12+
cin >> s;
13+
string s1;
14+
int ans = 0;
15+
if (s[0] == '_')
16+
{
17+
s1 = "^";
18+
ans++;
19+
}
20+
for (int i = 0; i < s.size(); i++)
21+
{
22+
if (s[i] == '_' && s1.back() == '_')
23+
{
24+
s1 += '^';
25+
}
26+
s1 += s[i];
27+
}
28+
if (s1.size() == 1){
29+
s1 += '^';
30+
}
31+
if (s1.back() == '_'){
32+
s1 += '^';
33+
}
34+
cout << s1.size() - s.size() << endl;
35+
return 0;
36+
}
37+
int main()
38+
{
39+
int testCase=1;
40+
cin>>testCase;
41+
while(testCase--){
42+
solve();
43+
}
44+
return 0;
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
vector<int> findColumnWidth(vector<vector<int>> &grid)
15+
{
16+
vector<int> ans;
17+
int n=grid.size();
18+
int m=grid[0].size();
19+
for(int j=0;j<m;j++){
20+
int maxo=0;
21+
for(int i=0;i<n;i++){
22+
int len = 0;
23+
if(grid[i][j]<0){
24+
len++;
25+
}
26+
string temp=to_string(abs(grid[i][j]));
27+
len+=temp.size();
28+
maxo = max(maxo, len);
29+
}
30+
ans.push_back(maxo);
31+
}
32+
return ans;
33+
}
34+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
class Solution
12+
{
13+
public:
14+
vector<long long> findPrefixScore(vector<int> &nums)
15+
{
16+
vector<long long> ans;
17+
long long maxo=0;
18+
for(int i=0;i<nums.size();i++){
19+
if(i==0){
20+
maxo=nums[i];
21+
ans.push_back(nums[i]*2);
22+
}
23+
else{
24+
maxo=max(maxo,(long long)nums[i]);
25+
ans.push_back(ans.back()+(nums[i]+maxo));
26+
}
27+
}
28+
return ans;
29+
}
30+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
written by Pankaj Kumar.
3+
country:-INDIA
4+
*/
5+
typedef long long ll ;
6+
const ll INF=1e18;
7+
const ll mod1=1e9+7;
8+
const ll mod2=998244353;
9+
//Add main code here
10+
11+
/**
12+
* Definition for a binary tree node.
13+
* struct TreeNode {
14+
* int val;
15+
* TreeNode *left;
16+
* TreeNode *right;
17+
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
18+
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
19+
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
20+
* };
21+
*/
22+
class Solution
23+
{
24+
public:
25+
26+
TreeNode *replaceValueInTree(TreeNode *root)
27+
{
28+
29+
queue<TreeNode*> q;
30+
TreeNode *dummy = root;
31+
root->val=0;
32+
q.push(dummy);
33+
while(q.size()){
34+
queue<TreeNode*> temp;
35+
map<TreeNode *, int> m;
36+
while(q.size()){
37+
if(q.front()->left!=nullptr){
38+
temp.push(q.front()->left);
39+
m[q.front()] += q.front()->left->val;
40+
}
41+
if(q.front()->right!=nullptr){
42+
temp.push(q.front()->right);
43+
m[q.front()] += q.front()->right->val;
44+
}
45+
q.pop();
46+
}
47+
int sum=0;
48+
for(auto x:m){
49+
sum+=x.second;
50+
}
51+
for(auto x:m){
52+
int temp2=0;
53+
if(x.first->left!=nullptr){
54+
temp2+=x.first->left->val;
55+
}
56+
if (x.first->right != nullptr)
57+
{
58+
temp2 += x.first->right->val;
59+
}
60+
temp2=sum-temp2;
61+
if (x.first->left != nullptr)
62+
{
63+
x.first->left->val=temp2;
64+
}
65+
if (x.first->right != nullptr)
66+
{
67+
x.first->right->val = temp2;
68+
}
69+
}
70+
71+
q=temp;
72+
}
73+
74+
return root;
75+
}
76+
};

0 commit comments

Comments
 (0)