diff --git a/string/1-pangrams.c b/string/1-pangrams.c new file mode 100644 index 0000000..cc536e0 --- /dev/null +++ b/string/1-pangrams.c @@ -0,0 +1,31 @@ +#include +#include + +int main(int argc, char const *argv[]) +{ + char small[26] = {0}; + char big[26] = {0}; + int i, n; + char s[1000]; + while (scanf("%s", &s[strlen(s)]) == 1); + n = strlen(s); + for (int i = 0; i < n; i++) { + if (s[i] >= 'a' && s[i] <= 'z') { + small[s[i] - 'a'] = 1; + } + else if (s[i] >= 'A' && s[i] <= 'Z') { + big[s[i] - 'A'] = 1; + } + } + + for (int i = 0; i < 26; i++) { + if (!(big[i] == 1 || small[i] == 1)) { + printf("not pangram"); + return 0; + } + } + + printf("pangram"); + + return 0; +} diff --git a/string/1-pangrams.php b/string/1-pangrams.php new file mode 100644 index 0000000..744c4b5 --- /dev/null +++ b/string/1-pangrams.php @@ -0,0 +1,17 @@ += $end) { + echo "-1\n"; + continue; + } + + $left = true; + $start_temp = $start; + $end_temp = $end; + $start_temp ++; + while ($start_temp < $end_temp) { + if ($str[$start_temp] == $str[$end_temp]) { + $start_temp ++; + $end_temp --; + } else { + $left = false; + break; + } + } + + echo $left ? $start : $end; + echo "\n"; +} diff --git a/string/11-reverse-shuffle-merge.php b/string/11-reverse-shuffle-merge.php new file mode 100644 index 0000000..9007e9a --- /dev/null +++ b/string/11-reverse-shuffle-merge.php @@ -0,0 +1,5 @@ + + +using namespace std; + +int main() +{ + int t,i; + cin>>t; + while(t--) + { + string str; + cin>>str; + int s = 0; + for(i=0 ; i< str.length()/2 ; i++) + { + s += abs(str[i] - str[str.length()-i-1]); + } + cout< +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + string s1, s2; + cin >> s1 >> s2; + int length = s1.length(); + int **array = new int*[length + 1]; + for (int i = 0; i < length + 1; ++i) + { + array[i] = new int[length + 1]; + } + + for (int i = 0; i < length; ++i) + { + for (int j = 0; j < length; ++j) + { + if (s1[i] == s2[j]) + { + array[i + 1][j + 1] = array[i][j] + 1; + } + else + { + array[i + 1][j + 1] = max(array[i + 1][j], array[i][j + 1]); + } + } + } + + cout << array[length][length] << endl; + + return 0; +} diff --git a/string/2-funny-string.cpp b/string/2-funny-string.cpp new file mode 100644 index 0000000..006025d --- /dev/null +++ b/string/2-funny-string.cpp @@ -0,0 +1,35 @@ +#include +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + string s, r; + int times; + cin >> times; + + for (int i = 0; i < times; ++i) + { + cin >> s; + int len = s.length(); + + bool funny = true; + for (int j = 1; j < len; ++j) + { + if (abs(s[len - j] - s[len - j - 1]) != abs(s[j] - s[j - 1])) { + funny = false; + break; + } + } + + if (funny) { + cout << "Funny" << endl; + } else { + cout << "Not Funny" << endl; + } + } + + return 0; +} diff --git a/string/2-funny-string.php b/string/2-funny-string.php new file mode 100644 index 0000000..06ad857 --- /dev/null +++ b/string/2-funny-string.php @@ -0,0 +1,20 @@ + +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int T; + cin >> T; + + while (T --) { + string str; + cin >> str; + + int ans = 0; + for (int i = 0; i < str.length() - 1; ++i) + { + if (str[i] == str[i + 1]) + ans ++; + } + + cout << ans << endl; + } + + return 0; +} diff --git a/string/3-alternating-characters.php b/string/3-alternating-characters.php new file mode 100644 index 0000000..cb50966 --- /dev/null +++ b/string/3-alternating-characters.php @@ -0,0 +1,17 @@ + +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + string str; + cin >> str; + int A[26]; + for (int i = 0; i < 26; ++i) + { + A[i] = 0; + } + for (int i = 0; i < str.length(); ++i) + { + A[str[i] - 'a'] ++; + } + + int sum = 0; + for (int i = 0; i < 26; ++i) + { + sum = sum + (A[i] % 2); + } + + if (sum >= 2) + { + cout << "NO" << endl; + } + else + { + cout << "YES" << endl; + } + + return 0; +} diff --git a/string/4-game-of-thrones.php b/string/4-game-of-thrones.php new file mode 100644 index 0000000..8ab595b --- /dev/null +++ b/string/4-game-of-thrones.php @@ -0,0 +1,43 @@ + +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int n; + int count = 0; + int letter[26] = {0}; + cin >> n; + + for (int i = 0; i < n; ++i) + { + string str; + cin >> str; + + for (int j = 0; j < str.length(); ++j) + { + if (letter[str[j] - 'a'] == i) + letter[str[j] - 'a'] ++; + } + } + + for (int i = 0; i < 26; ++i) + { + if (letter[i] == n) + count ++; + } + + cout << count << endl; + + return 0; +} diff --git a/string/5-gem-stones.php b/string/5-gem-stones.php new file mode 100644 index 0000000..9609a44 --- /dev/null +++ b/string/5-gem-stones.php @@ -0,0 +1,25 @@ + +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + string one; + string two; + int count = 0; + + cin >> one >> two; + + int some[26] = {0}; + int other[26] = {0}; + + for (int i = 0; i < one.length(); ++i) + { + some[one[i] - 'a'] ++; + } + + for (int i = 0; i < two.length(); ++i) + { + other[two[i] - 'a'] ++; + } + + for (int i = 0; i < 26; ++i) + { + count += abs(some[i] - other[i]); + } + + cout << count << endl; + + return 0; +} diff --git a/string/6-make-it-anagram.php b/string/6-make-it-anagram.php new file mode 100644 index 0000000..3cd6eb8 --- /dev/null +++ b/string/6-make-it-anagram.php @@ -0,0 +1,36 @@ + +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int T; + cin >> T; + + while (T --) { + int count = 0; + int letter[26] = {0}; + string s; + cin >> s; + + int length = s.length(); + + if (length % 2 == 1) { + cout << -1 << endl; + continue; + } + + for (int i = 0; i < length / 2; ++i) + { + letter[s[i] - 'a'] ++; + } + + for (int i = length / 2; i < length; ++i) + { + letter[s[i] - 'a'] --; + } + + for (int i = 0; i < 26; ++i) + { + count += abs(letter[i]); + } + + cout << count / 2 << endl; + } + + return 0; +} diff --git a/string/7-anagram.php b/string/7-anagram.php new file mode 100644 index 0000000..965ca44 --- /dev/null +++ b/string/7-anagram.php @@ -0,0 +1,34 @@ + +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int T; + cin >> T; + + while (T --) { + bool exists = false; + string letters = "abcdefghijklmnopqrstuvwxyz"; + + string str1; + string str2; + cin >> str1 >> str2; + + for (int i = 0; i < 26; ++i) + { + if (str1.find(letters[i]) != string::npos && str2.find(letters[i]) != string::npos) { + exists = true; + break; + } + } + + if (exists) + { + cout << "YES\n"; + } + else + { + cout << "NO\n"; + } + } + + return 0; +} diff --git a/string/8-two-string.php b/string/8-two-string.php new file mode 100644 index 0000000..d6a471a --- /dev/null +++ b/string/8-two-string.php @@ -0,0 +1,41 @@ + +#include +#include +#include + +using namespace std; + +int main(int argc, char const *argv[]) +{ + int T; + cin >> T; + + while (T --) { + string s; + cin >> s; + int length = s.length(); + + int step = 1; + map anagrams; + + while (step < length) { + for (int i = 0; i < length - step + 1; ++i) + { + string str = s.substr(i, step); + sort(str.begin(), str.end()); + + if (anagrams.find(str) != anagrams.end()) + { + anagrams[str] ++; + } + else + { + anagrams[str] = 1; + } + } + step ++; + } + + int count = 0; + map::iterator it; + for (it = anagrams.begin(); it != anagrams.end(); it ++) + { + if (it->second >= 2) { + count += (it->second * (it->second - 1)) / 2; + } + } + + cout << count << endl; + } + + return 0; +} diff --git a/string/a.out b/string/a.out new file mode 100755 index 0000000..baf813f Binary files /dev/null and b/string/a.out differ