File tree Expand file tree Collapse file tree 3 files changed +132
-0
lines changed
CompetitiveProgramming/HackerEarth/Algorithms/String Expand file tree Collapse file tree 3 files changed +132
-0
lines changed Original file line number Diff line number Diff line change 1+ # Given a string 'S' , u need to tell whether it is 'sumit's string or not'.
2+ #
3+ # A string is called 'Sumit's String' , if distance between adjacent character is 1.
4+ #
5+ # Consider that the alphabets are arranged in cyclic manner from 'a' to 'z'. distance between any character
6+ # 'x' and 'y' will be defined as minimum number of steps it takes 'x' to reach 'y'. Here, character 'x' can
7+ # start moving clockwise or anti-clockwise in order to reach at position where character 'y' is placed.
8+ #
9+ # Print 'YES' if it is Sumit's string else print 'NO', for each yest case.
10+ #
11+ # Input :
12+ #
13+ # test cases, t
14+ # string , s
15+ # Output:
16+ #
17+ # Desired O/p
18+ #
19+ # Constraints :
20+ #
21+ # string length<=250
22+ # string has only lower case letters
23+ #
24+ # SAMPLE INPUT
25+ # 3
26+ # aba
27+ # zza
28+ # bcd
29+ #
30+ # SAMPLE OUTPUT
31+ # YES
32+ # NO
33+ # YES
34+
35+ for _ in range (int (input ())):
36+ string = input ()
37+ sumit_string = True
38+ check = 'abcdefghijklmnopqrstuvwxyz'
39+ for i in range (len (string ) - 1 ):
40+ check_first = check .find (string [i ]) + 1
41+ check_second = check .find (string [i + 1 ]) + 1
42+ if abs (check_second - check_first ) == 1 or abs (check_second - check_first ) == 25 :
43+ continue
44+ else :
45+ sumit_string = False
46+ break
47+
48+ if sumit_string :
49+ print ('YES' )
50+ else :
51+ print ('NO' )
Original file line number Diff line number Diff line change 1+ # Given a string S. Your task is to remove all duplicates characters from the string S
2+ #
3+ # NOTE:
4+ # 1.) Order of characters in output string should be same as given in input string.
5+ # 2.) String S contains only lowercase characters ['a'-'z'].
6+ #
7+ # input:
8+ # Input contain a single string S.
9+ #
10+ # Output:
11+ # Print the string S with no any duplicate characters.
12+ #
13+ # Constraints:
14+ # Test Files 1 to 5:
15+ # 1<=|S|<=100
16+ # Test Files 6 to 10:
17+ # 1<=|S|<=100000
18+ #
19+ # Sample Output #1
20+ # hacker
21+ #
22+ # Sample Output #1
23+ # hacker
24+ #
25+ # Sample Input #2
26+ # hackerearth
27+ #
28+ # Sample Output #2
29+ # hackert
30+ #
31+ # Sample Input #3
32+ # programming
33+ #
34+ # Sample Output #3
35+ # progamin
36+
37+ string = list (input ())
38+ result = []
39+ for i in range (len (string )):
40+ if string [i ] not in result :
41+ result .append (string [i ])
42+
43+ print ('' .join (result ))
Original file line number Diff line number Diff line change 1+ # Given a string, convert it into its number form .
2+ #
3+ # A or a -> 1
4+ # B or b -> 2
5+ # C or c -> 3
6+ # . . .
7+ # Z or z -> 26
8+ # space -> $
9+ # Input:
10+ #
11+ # test cases, t
12+ # string , s
13+ # Output:
14+ #
15+ # Desired O/p
16+ #
17+ # Constraints: string length <=200
18+ #
19+ # SAMPLE INPUT
20+ # 2
21+ # AMbuj verma
22+ # Aaaa bBBB
23+ #
24+ # SAMPLE OUTPUT
25+ # 11322110$22518131
26+ # 1111$2222
27+
28+ for _ in range (int (input ())):
29+ string = input ()
30+ check = 'abcdefghijklmnopqrstuvwxyz'
31+ result = []
32+ for i in range (len (string )):
33+ if string [i ].lower () != ' ' :
34+ result .append (check .find (string [i ].lower ()) + 1 )
35+ else :
36+ result .append ('$' )
37+
38+ print ('' .join ([str (i ) for i in result ]))
You can’t perform that action at this time.
0 commit comments