diff --git a/allalgorithms/string/counting_valleys.py b/allalgorithms/string/counting_valleys.py new file mode 100644 index 0000000..25761ef --- /dev/null +++ b/allalgorithms/string/counting_valleys.py @@ -0,0 +1,31 @@ +''' +Counting valleys deals with strings. One has to count the number of valleys and Hills in the given string and return the position of traveller at end w.r.t the start point. +'U' is treated as 'the traveller came across a hill' and 'D' denotes that he came across a valley. + +Input is guranteed as a string with 'U', and 'D' with an integer having the value of length of input string. + +Output should be a single integer that denotes the number of valleys traveller walked through during his hike. + +Example : +Input = 8 + UDDDUDUU + +Output = 1 +''' + +import sys +n = int(input()) +s = input() + +m = 0 +v = 0 + +for i in s: + if i == 'U': + m += 1 + if m == 0: + v += 1 + else: + m -= 1 +print(v) + diff --git a/allalgorithms/string/pangrams.py b/allalgorithms/string/pangrams.py new file mode 100644 index 0000000..951616b --- /dev/null +++ b/allalgorithms/string/pangrams.py @@ -0,0 +1,12 @@ +# Algorithm to check the string is pangram or not + +alpha = "abcdefghijklmnopqrstuvwxyz " + +def isPangram(s): + for i in alpha: + if i not in s: + return "not pangram" + return "pangram" +s = input().lower() +print(isPangram(s)) +