From 9992d5c43802f967b18175951d44aa31774e0ba4 Mon Sep 17 00:00:00 2001 From: jahnavi Date: Mon, 4 Nov 2019 22:22:27 +0530 Subject: [PATCH 1/2] Adding counting valleys algorithm, that deals with strings --- allalgorithms/string/counting_valleys.py | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 allalgorithms/string/counting_valleys.py 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) + From f5f9ea8f191440bcea2c6e224445dc4a1ed348a7 Mon Sep 17 00:00:00 2001 From: jahnavi Date: Mon, 4 Nov 2019 22:23:11 +0530 Subject: [PATCH 2/2] Adding pangrams problem for strings --- allalgorithms/string/pangrams.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 allalgorithms/string/pangrams.py 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)) +