forked from GeeksforGeeks-VIT-Bhopal/GeekWeek-Local
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpharshitha-vr-unique-codingninjas-dsa-strings
112 lines (83 loc) · 2.13 KB
/
pharshitha-vr-unique-codingninjas-dsa-strings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <iostream>
using namespace std;
int findSum(string str)
{
string temp = "";
int sum = 0;
for (char ch : str) {
if (isdigit(ch))
temp += ch;
else {
sum += atoi(temp.c_str());
temp = "";
}
}
return sum + atoi(temp.c_str());
} A
int main()
{
string str = "12abc20yz68";
cout << findSum(str);
return 0;
}
........................................................................................
#include <bits/stdc++.h>
#include <time.h>
using namespace std;
int isPossible(string str)
{
unordered_map<char, int> freq;
int max_freq = 0;
for (int j = 0; j < (str.length()); j++) {
freq[str[j]]++;
if (freq[str[j]] > max_freq)
max_freq = freq[str[j]];
}
if (max_freq <= (str.length() - max_freq + 1))
return true;
return false;
}
int main()
{
string str = "";
if (isPossible(str))
cout << "Yes";
else
cout << "No";
return 0;
}
..............................................................................
import java.util.*;
class VRU{
static void printSubStr(String str, int low, int high)
{
for (int i = low; i <= high; ++i)
System.out.print(str.charAt(i));
}
static int longestPalSubstr(String str)
{
int n = str.length();
int maxLength = 1, start = 0;
for (int i = 0; i < str.length(); i++) {
for (int j = i; j < str.length(); j++) {
int flag = 1;
for (int k = 0; k < (j - i + 1) / 2; k++)
if (str.charAt(i + k) != str.charAt(j - k))
flag = 0;
if (flag!=0 && (j - i + 1) > maxLength) {
start = i;
maxLength = j - i + 1;
}
}
}
System.out.print("Longest palindrome subString is: ");
printSubStr(str, start, start + maxLength - 1);
return maxLength;
}
public static void main(String[] args)
{
String str = "a,e,i,o,u";
System.out.print("\nLength is: "
+ longestPalSubstr(str));
}
}