Làm thế nào về bạn chỉ cần cắt chuỗi khi in [hoặc gán một biến mới] và xóa start = word[0:][0]
:
trans = input["enter a sentence "]
trans = trans.lower[]
t_list = trans.split[]
for word in t_list:
print[word[0]]
Điều này hoạt động bởi vì bạn nhận được một danh sách chứa tất cả các giá trị của chuỗi [theo mặc định split[]
chia không gian trắng], tiếp theo bạn bắt đầu thông qua danh sách đó [điều này trả về một ký tự duy nhất] và sau đó nhận được giá trị của ký tự đầu tiên của chuỗi.
Bạn cũng có thể sử dụng trans = input["enter a sentence "].lower[].split[]
thay vì xác định lại trans
thành một biến mới mỗi lần.
split[]
86
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
split[]
88str is given which contains lowercase English letters and spaces. It may contain multiple spaces. Get the first letter of every word and return the result as a string. The result should not contain any space.Examples:
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc
Nguồn: //www.geeksforgeek.org/amazon-interview-set-8-2/
Ý tưởng là đi qua từng ký tự của Str Str và duy trì một biến boolean, ban đầu được đặt là đúng. Bất cứ khi nào chúng tôi gặp không gian, chúng tôi đặt biến Boolean là đúng. Và nếu chúng ta gặp bất kỳ ký tự nào khác ngoài không gian, chúng ta sẽ kiểm tra biến Boolean, nếu nó được đặt đúng như bản sao điều lệ cho chuỗi đầu ra và đặt biến Boolean là sai. Nếu biến boolean được đặt sai, không làm gì cả. & Nbsp;
Algorithm:
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.
Implementation:
C++
#include
using
namespace
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc1
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc5
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc8
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
0 start = word[0:][0]
1start = word[0:][0]
2start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
9 start = word[0:][0]
0 split[]
1start = word[0:][0]
2 split[]
31. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
start = word[0:][0]
31. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
4split[]
9
start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
trans = input["enter a sentence "].lower[].split[]
221. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
5Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 trans
0trans = input["enter a sentence "].lower[].split[]
5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.5
trans
3Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans
6trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
#include
0Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 #include
3trans = input["enter a sentence "].lower[].split[]
5
Java
#include
5 #include
6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
#include
9 using
0Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
using
4Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc5
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
using
8 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.5
namespace
6namespace
7namespace
81. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
4start = word[0:][0]
0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc03
start = word[0:][0]
2start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
5
start = word[0:][0]
4start = word[0:][0]
9 start = word[0:][0]
0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc17
start = word[0:][0]
2 split[]
31. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc25
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
trans = input["enter a sentence "].lower[].split[]
2Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
51. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
9 trans
0Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc42
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc43
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc47
trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc51
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5trans = input["enter a sentence "].lower[].split[]
5
Python 3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc55
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc56
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc58
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc60
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc5
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc64
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc66
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc69
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc70
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc71
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc73
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc76
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
0 1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc81
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
start = word[0:][0]
2Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc58
start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc64
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc66
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc91
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc94__
start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc60
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.05
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.09
start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc64
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.13
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.16
start = word[0:][0]
0
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.18
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.21
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.22
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.28
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.29
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.31
C#
using
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.33
#include
5 #include
6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
#include
9 using
0Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
using
4Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc5
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
using
8 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.4
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.5
namespace
6namespace
7namespace
81. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
4start = word[0:][0]
0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc03
start = word[0:][0]
2start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
5
start = word[0:][0]
4start = word[0:][0]
9 start = word[0:][0]
0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc17
start = word[0:][0]
2 split[]
31. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.82
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
9 trans
0start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
51. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
9 trans
0Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc42
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc43
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc47
trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
08Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5trans = input["enter a sentence "].lower[].split[]
5
Python 3
start = word[0:][0]
12
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc55
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc56
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc57
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc58
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
19Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc5
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
231. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc60
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
4start = word[0:][0]
0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc03
start = word[0:][0]
2start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
5
start = word[0:][0]
4start = word[0:][0]
9 start = word[0:][0]
0
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc17
start = word[0:][0]
2 split[]
31. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.0
start = word[0:][0]
3start = word[0:][0]
4
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.82
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc08
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc9
trans = input["enter a sentence "].lower[].split[]
2Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
51. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
9 trans
0Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
start = word[0:][0]
70trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
73start = word[0:][0]
74
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc42
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc43
Python 3 O[n]
Auxiliary space: O[n].
Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
55 Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
56Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
57Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
58This approach uses the StringBuilder class of Java. In this approach, we will first split the input string based on the spaces. The spaces in the strings can be matched using a regular expression. The split strings are stored in an array of strings. Then we can simply append the first character of each split string in the String
Builder object.
Implementation:
C++
start = word[0:][0]
76
using
namespace
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc0
start = word[0:][0]
80start = word[0:][0]
81 start = word[0:][0]
82
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
start = word[0:][0]
81 start = word[0:][0]
86Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
start = word[0:][0]
88Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
start = word[0:][0]
90start = word[0:][0]
91start = word[0:][0]
92start = word[0:][0]
93start = word[0:][0]
94Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
start = word[0:][0]
96 start = word[0:][0]
97Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
split[]
011. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
start = word[0:][0]
90start = word[0:][0]
91split[]
05start = word[0:][0]
93start = word[0:][0]
94Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
5Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
split[]
11
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
split[]
141. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
split[]
16Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 split[]
19trans = input["enter a sentence "].lower[].split[]
5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.5
trans
3Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
start = word[0:][0]
81 split[]
26trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
split[]
30Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 #include
3trans = input["enter a sentence "].lower[].split[]
5
Java
#include
5 #include
6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
split[]
38split[]
39 #include
9 split[]
41split[]
42 split[]
43
split[]
38
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 split[]
47split[]
38
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
split[]
51split[]
52start = word[0:][0]
941. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
split[]
561. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
4split[]
60namespace
7split[]
62
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
5start = word[0:][0]
73trans = input["enter a sentence "].lower[].split[]
9 split[]
67
split[]
38trans = input["enter a sentence "].lower[].split[]
5
split[]
38
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc42
split[]
74split[]
38
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
73split[]
78split[]
79
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
start = word[0:][0]
73split[]
82
split[]
38trans = input["enter a sentence "].lower[].split[]
5
trans = input["enter a sentence "].lower[].split[]
5
Python3
split[]
86
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
split[]
88Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc55
split[]
90split[]
91Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc58
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
split[]
94Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
split[]
91split[]
97start = word[0:][0]
93start = word[0:][0]
3Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
trans = input["enter a sentence "].lower[].split[]
022____170 trans = input["enter a sentence "].lower[].split[]
041. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
06namespace
7trans = input["enter a sentence "].lower[].split[]
08Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 trans = input["enter a sentence "].lower[].split[]
11start = word[0:][0]
0
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.18
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
trans = input["enter a sentence "].lower[].split[]
161. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.22
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
split[]
91 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
trans
7Các
C#
using
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.33
using
trans = input["enter a sentence "].lower[].split[]
34
#include
5 #include
6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
split[]
38split[]
39 #include
9 split[]
41split[]
42 split[]
43
split[]
38
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 split[]
47Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
48start = word[0:][0]
2start = word[0:][0]
941. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
split[]
51split[]
52start = word[0:][0]
941. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
59
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
5start = word[0:][0]
73trans = input["enter a sentence "].lower[].split[]
9 split[]
67
trans = input["enter a sentence "].lower[].split[]
5
split[]
38
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc40
#include
9 Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc42
split[]
74Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
split[]
78trans
7Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc6
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
76trans = input["enter a sentence "].lower[].split[]
5
trans = input["enter a sentence "].lower[].split[]
5
split[]
86Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
61 split[]
88
start = word[0:][0]
12
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc55
split[]
90split[]
91Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc58
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
split[]
94Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc61
split[]
91split[]
97start = word[0:][0]
93start = word[0:][0]
3Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc2
Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.3
trans = input["enter a sentence "].lower[].split[]
022____170 trans = input["enter a sentence "].lower[].split[]
041. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
93start = word[0:][0]
4trans = input["enter a sentence "].lower[].split[]
95
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.9
trans = input["enter a sentence "].lower[].split[]
97Input : str = "geeks for geeks" Output : gfg Input : str = "happy coding" Output : hc3
trans = input["enter a sentence "].lower[].split[]
9 split[]
19trans = input["enter a sentence "].lower[].split[]
5
1. Traverse string str. And initialize a variable v as true. 2. If str[i] == ' '. Set v as true. 3. If str[i] != ' '. Check if v is true or not. a] If true, copy str[i] to output string and set v as false. b] If false, do nothing.5
trans
3trans
06
start = word[0:][0]
75
Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
3start = word[0:][0]
81 split[]
26trans
7Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
6 O[n2]
Auxiliary space: O[n].
Input : str = "geeks for geeks"
Output : gfg
Input : str = "happy coding"
Output : hc
3trans = input["enter a sentence "].lower[].split[]
9 #include
3: Using boundary checker, refer //www.geeksforgeeks.org/get-first-letter-word-string-using-regex-java/
JavaAarti_Rathi and Anuj Chauhan. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to . See your article appearing on the GeeksforGeeks main page and help other Geeks.