WhiteHat Coding
Відкрити в Telegram
650
Підписники
Немає даних24 години
-27 днів
-330 день
Архів дописів
Share this channel all are free
help us to grow..and help students to get placed..✅
@whitehatcoding ❤️
Beauty code Python 👨💻
share @whitehatcoding ❤️
Sharing = Caring = Spreading Happiness 😍❤️
Anybody have any exam
share your Questions here
i will share codes/ans here for all for free for spreading happiness 😊
Share with your friends and in college groups
Sharing = caring = spreading happiness
https://t.me/whitehatcoding
https://t.me/whitehatcoding
share ✅ share ✅ share ✅
Repost from IBM EXAM_000
#include <bits/stdc++.h>
using namespace std;
int beauty(int n, int m, string s, vector<int> &x, vector<int> &y)
{
unordered_map<char, int> count;
vector<int> vec(n);
vector<vector<int>> graph(n);
for (int i = 0; i < n; i++)
count[s[i]]++;
for (int i = 0; i < n; i++)
vec[i] = count[s[i]];
for (int i = 0; i < m; i++)
graph[x[i] - 1].push_back(y[i] - 1);
int max_b = 0;
for (int i = 0; i < n; i++)
max_b = max(max_b, vec[i]);
if (max_b == 1)
return -1;
vector<bool> visited(n, false);
int res = -1;
for (int i = 0; i < n; i++)
{
if (!visited[i] && vec[i] == max_b)
{
vector<int> stack;
stack.push_back(i);
while (!stack.empty())
{
int node = stack.back();
stack.pop_back();
if (!visited[node])
{
visited[node] = true;
for (int nei : graph[node])
{
if (!visited[nei])
{
stack.push_back(nei);
}
}
}
}
res = max_b;
break;
}
}
return res;
}
int main()
{
int n, m;
string s;
vector<int> x, y;
cin >> n >> m >> s;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
cout << beauty(n, m, s, x, y) << endl;
}
Beauty code C++ ✅
Repost from IBM EXAM_000
import java.util.*;
public class Main {
public static int beauty(int m, int n, String s, int[] u, int[] v) {
Map> graph = new HashMap<>();
for (int i = 0; i < m; i++) {
int node1 = u[i];
int node2 = v[i];
graph.putIfAbsent(node1, new ArrayList<>());
graph.putIfAbsent(node2, new ArrayList<>());
graph.get(node1).add(node2);
graph.get(node2).add(node1);
}
int maxBeauty = 0;
for (int start : graph.keySet()) {
int[] distances = new int[n + 1];
Arrays.fill(distances, Integer.MAX_VALUE);
Queue queue = new LinkedList<>();
queue.offer(start);
distances[start] = 0;
while (!queue.isEmpty()) {
int node = queue.poll();
for (int neighbor : graph.get(node)) {
if (distances[neighbor] == Integer.MAX_VALUE) {
distances[neighbor] = distances[node] + 1;
queue.offer(neighbor);
}
}
}
int beauty = 26;
int currentBeauty = 0;
for (int i = 1; i <= n; i++) {
if (distances[i] == Integer.MAX_VALUE) {
continue;
}
char c = s.charAt(i - 1);
if (Character.isAlphabetic(c)) {
currentBeauty += (c - 'a' + 1) * beauty;
beauty--;
}
}
maxBeauty = Math.max(maxBeauty, currentBeauty);
}
return maxBeauty > 1000 ? -1 : maxBeauty;
}
}
beauty code Java..✅
Share with your friends and in college groups
Sharing = caring = spreading happiness😊
https://t.me/whitehatcoding
https://t.me/whitehatcoding
share ✅ share ✅ share ✅
#include <bits/stdc++.h>
using namespace std;
int beauty(int n, int m, string s, vector<int> &x, vector<int> &y)
{
unordered_map<char, int> count;
vector<int> vec(n);
vector<vector<int>> graph(n);
for (int i = 0; i < n; i++)
count[s[i]]++;
for (int i = 0; i < n; i++)
vec[i] = count[s[i]];
for (int i = 0; i < m; i++)
graph[x[i] - 1].push_back(y[i] - 1);
int max_b = 0;
for (int i = 0; i < n; i++)
max_b = max(max_b, vec[i]);
if (max_b == 1)
return -1;
vector<bool> visited(n, false);
int res = -1;
for (int i = 0; i < n; i++)
{
if (!visited[i] && vec[i] == max_b)
{
vector<int> stack;
stack.push_back(i);
while (!stack.empty())
{
int node = stack.back();
stack.pop_back();
if (!visited[node])
{
visited[node] = true;
for (int nei : graph[node])
{
if (!visited[nei])
{
stack.push_back(nei);
}
}
}
}
res = max_b;
break;
}
}
return res;
}
int main()
{
int n, m;
string s;
vector<int> x, y;
cin >> n >> m >> s;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
x.push_back(a);
y.push_back(b);
}
cout << beauty(n, m, s, x, y) << endl;
}
beauty code C++✅
Accolite code all uploaded with all languages check scroll above...👆👆
share to ur friends...✅❤️
Beauty code Java ✅
Join @whitehatcoding ❤️
share @Coding_000👨💻
Please share to ur friends✅
Beauty code C language ✅
Follow @Whitehatcoding❤️
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,turn=1;
cin>>n;
vector<int>arr;
map<int, int>mp;
int temp;
for(int i=0; i<n; i++){
cin>>temp;
arr.push_back(temp);
}
sort(arr.begin(), arr.end());
reverse(arr.begin(),arr.end());
for(int i=0; i<n; i++){
mp[arr[i]]++;
}
for(auto it:mp){
if(it.second%2){
turn=0;
break;
}
}
if(turn)
cout<<"Zenyk"<<endl;
else
cout<<"Marichka"<<endl;
}
int main() {
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Take not less C++✅
@whitehatcoding ❤️
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
for(int i=1; i<n; i++)
cout<<i+1<<" ";
cout<<1<<endl;
}
int main() {
int t;
cin>>t;
while(t--)
solve();
return 0;
}
Permutation and Modulus C++✅ @whitehatcoding ❤️
#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s;
cin>>s;
unordered_set<char>st;
int flag=0;
for(int i=0; i<n; i++){
if(st.find(s[i])!=st.end()){
flag=1;
break;
}
st.insert(s[i]);
}
if(flag)
cout<<n-2<<endl;
else
cout<<-1<<endl;
}
}
Bi_lindrome solution C++✅
@whitehatcoding❤️
