Làm ơn đăng nhập để tiếp tục
Đăng nhậpBài 18 trên 39 • 1 lượt ủng hộ • 8. 45 phút
Trong video này chúng ta sẽ nghiên cứu về hai chương trình thao tác với chuỗi
Crack GATE & ESE với Unacademy
Nhận đăng ký và truy cập các khóa học trực tiếp và được ghi lại không giới hạn từ các nhà giáo dục tốt nhất của Ấn ĐộTìm hiểu thêmChương trình C để in các nguyên âm trong một chuỗi và vị trí của chúng. Chúng ta cần tìm tất cả các nguyên âm [chữ thường và chữ hoa] trong một chuỗi đã cho và vị trí của nó
Ví dụ,
Đầu vào. Chào thế giới
đầu ra
Nguyên âm. điện tử tại địa điểm. 1
Nguyên âm. o tại địa điểm. 4
Nguyên âm. o tại địa điểm. 7
Giải pháp tìm nguyên âm trong Chuỗi
Giải pháp rất đơn giản, chúng ta có thể lưu chuỗi vào một mảng char. Truy xuất từng ký tự bằng vòng lặp for và so sánh chúng với tất cả các nguyên âm tôi. e. a, e, i, o, u, A, E, I, O, U. Nếu ký tự khớp, chúng ta có thể in định vị và ký tự
GHI CHÚ
Để đọc chuỗi đầu vào e. g. Hello World, trong hàm scanf, chúng ta cần sử dụng biểu thức scanf[“%[^\n]s”, str]; . Nó sẽ đọc chuỗi bao gồm cả khoảng trắng. Nếu chúng ta sử dụng đơn giản như scanf[“%s”, str]; . g. trong thế giới hello, chỉ có hello sẽ được đọc bởi scanf
Cho một chuỗi str. Nhiệm vụ là sửa đổi chuỗi bằng cách hoán đổi hai ký tự liền kề nếu cả hai đều là nguyên âm hoặc cả hai đều là phụ âm
ví dụ.
Đầu vào. str = “geeksforgeeks”
Đầu ra. geesfkogreesk
Các chữ cái 'e' và 'e' trong geeksforgeeks là các nguyên âm nên chúng được hoán đổi để chuỗi trở thành geeksforgeeks.
Các chữ cái 'k' và 's' trong geeksforgeeks là phụ âm nên chúng được hoán đổi để chuỗi trở thành geeksforgeeks.
Các chữ cái 'k' và 'f' trong geekkforgeeks là phụ âm nên chúng được hoán đổi để chuỗi trở thành geesfkorgeeks.
Các chữ cái 'r' và 'g' trong geesfkorgeeks là phụ âm nên chúng được hoán đổi để chuỗi trở thành geesfkorgeeks.
Các chữ cái 'e' và 'e' trong geekfogreeks là các nguyên âm nên chúng được đổi chỗ để chuỗi trở thành geekfogreeks.
Các chữ cái 'k' và 's' trong geekfogreesk là các nguyên âm nên chúng được hoán đổi để chuỗi trở thành geekfogreesk.Đầu vào. str = “gefeg”
Đầu ra. gefeg
Không có nguyên âm hoặc phụ âm tiếp diễn.
Khuyến khích. Vui lòng thử cách tiếp cận của bạn trên {IDE} trước, trước khi chuyển sang giải pháp
Cách tiếp cận.
- Duyệt qua các ký tự trong chuỗi
- Xem xét ký tự hiện tại và ký tự tiếp theo
- Nếu cả hai ký tự là phụ âm hoặc cả hai ký tự là nguyên âm
- Sau đó trao đổi các ký tự
- Khác tiếp tục quá trình cho đến khi kết thúc chuỗi
Dưới đây là việc thực hiện các phương pháp trên.
C++
// C++ implementation of the above approach
#include
using
namespace
std;
// Function to check if a character is a vowel
bool
isVowel[
char
// C++ implementation of the above approach
0
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2// C++ implementation of the above approach
3// C++ implementation of the above approach
4// C++ implementation of the above approach
5
// C++ implementation of the above approach
2// C++ implementation of the above approach
7 // C++ implementation of the above approach
8// C++ implementation of the above approach
9 #include
0#include
1 #include
0#include
3
#include
4#include
0#include
6 #include
0#include
8#include
9
using
0using
1 using
2using
3
// C++ implementation of the above approach
2using
1 using
6using
3
using
8
using
9
namespace
0
namespace
1
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2____34
// C++ implementation of the above approach
2namespace
6 namespace
7namespace
8 namespace
9
using
0std;
1
using
0____43
using
0// C++ implementation of the above approach
7 std;
6
std;
7std;
8
std;
7// Function to check if a character is a vowel
0
std;
7// Function to check if a character is a vowel
2
// C++ implementation of the above approach
2using
8
// C++ implementation of the above approach
2using
1 // Function to check if a character is a vowel
7
using
8
// Function to check if a character is a vowel
9
namespace
8 bool
1
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2bool
4bool
5using
3
// C++ implementation of the above approach
2bool
8
// C++ implementation of the above approach
2using
1 isVowel[
1
using
8
Java
isVowel[
3
isVowel[
4 isVowel[
5
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2isVowel[
8
// C++ implementation of the above approach
2char
0
// C++ implementation of the above approach
2char
2 char
3 isVowel[
char
// C++ implementation of the above approach
0
// C++ implementation of the above approach
2// C++ implementation of the above approach
1
using
0// C++ implementation of the above approach
00
using
0// C++ implementation of the above approach
7 // C++ implementation of the above approach
8// C++ implementation of the above approach
9 #include
0#include
1 #include
0#include
3
// C++ implementation of the above approach
09#include
0#include
6 #include
0#include
8#include
9
using
0// C++ implementation of the above approach
1
std;
7using
1 using
2using
3
using
0using
8
using
0using
1 using
6____23
// C++ implementation of the above approach
2using
8
// C++ implementation of the above approach
2using
9
// C++ implementation of the above approach
2namespace
0
// C++ implementation of the above approach
2____82 // C++ implementation of the above approach
35____8 // C++ implementation of the above approach
37
// C++ implementation of the above approach
2// C++ implementation of the above approach
1
using
0
using
0// C++ implementation of the above approach
42
using
0// C++ implementation of the above approach
44
using
0namespace
6 namespace
7namespace
8 // C++ implementation of the above approach
49// C++ implementation of the above approach
50// C++ implementation of the above approach
51// C++ implementation of the above approach
52// C++ implementation of the above approach
53
using
0// C++ implementation of the above approach
1
std;
7char
// C++ implementation of the above approach
3// C++ implementation of the above approach
50using
3
std;
7
std;
7std;
1
std;
7std;
3
std;
7// C++ implementation of the above approach
7 // C++ implementation of the above approach
68// C++ implementation of the above approach
52// C++ implementation of the above approach
70
// C++ implementation of the above approach
71// C++ implementation of the above approach
72____052// C++ implementation of the above approach
74
std;
7// C++ implementation of the above approach
1
// C++ implementation of the above approach
71
// C++ implementation of the above approach
71// Function to check if a character is a vowel
0
_______071____081
_______071____083____052// C++ implementation of the above approach
85
_______071____087____052// C++ implementation of the above approach
89
std;
7using
8
using
0using
8
using
0using
1 // C++ implementation of the above approach
96
// C++ implementation of the above approach
2using
8
// C++ implementation of the above approach
2____59
________ 02 ________ 102 ________ 82 ________ 104 ________ 105
// C++ implementation of the above approach
2// C++ implementation of the above approach
1
using
0#include
09____65using
3
using
0____113
// C++ implementation of the above approach
2using
8
using
8
#include
17
Trăn 3
#include
18
#include
19
#include
20 #include
21
// C++ implementation of the above approach
2____123#include
24 #include
25
// C++ implementation of the above approach
2// C++ implementation of the above approach
7 #include
28#include
24#include
24 // C++ implementation of the above approach
9 #include
32 #include
23#include
24#include
24 #include
1 #include
32 #include
23#include
24#include
24 #include
3
#include
4#include
32 #include
23_______124#include
24 #include
6 #include
32 #include
23#include
24#include
24 #include
8#include
53
using
0using
1 #include
56using
3
// C++ implementation of the above approach
2using
1 #include
60using
3
#include
62
#include
63
#include
20 #include
65
// C++ implementation of the above approach
2
// C++ implementation of the above approach
2#include
68
// C++ implementation of the above approach
2namespace
6 #include
71#include
72 #include
73namespace
7#include
75#include
76#include
77 // C++ implementation of the above approach
52#include
53
using
0#include
81
using
0____183
using
0// C++ implementation of the above approach
7 #include
86#include
87 #include
88#include
89 // C++ implementation of the above approach
52// C++ implementation of the above approach
70#include
32
using
0______37#include
95#include
96#include
87 #include
95#include
99#include
89 // C++ implementation of the above approach
52using
02
std;
7using
04
std;
7using
06
using
07using
08#include
89 // C++ implementation of the above approach
52using
11#include
24 using
13#include
89 // C++ implementation of the above approach
52using
16
using
17using
18
// C++ implementation of the above approach
2
// C++ implementation of the above approach
2____221____124 using
23
// C++ implementation of the above approach
2using
1 using
26
using
27
// C++ implementation of the above approach
7 using
29____124#include
24 using
32 using
33
// C++ implementation of the above approach
2
// C++ implementation of the above approach
2______221____124 bool
5using
3
// C++ implementation of the above approach
2____241using
42using
43using
44
// C++ implementation of the above approach
2
using
46
C#
using
47
using
using
49
isVowel[
4 isVowel[
5
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2isVowel[
8
// C++ implementation of the above approach
2char
0
// C++ implementation of the above approach
2char
2 bool
isVowel[
char
// C++ implementation of the above approach
0
// C++ implementation of the above approach
2// C++ implementation of the above approach
1
using
0____03____8using
68
using
0// C++ implementation of the above approach
7 // C++ implementation of the above approach
8// C++ implementation of the above approach
9 #include
0#include
1 #include
0#include
3
// C++ implementation of the above approach
09#include
0#include
6 #include
0#include
8#include
9
using
0// C++ implementation of the above approach
1
std;
7using
1 using
2using
3
using
0using
8
using
0using
1 using
6____23
// C++ implementation of the above approach
2using
8
// C++ implementation of the above approach
2using
9
// C++ implementation of the above approach
2namespace
0
// C++ implementation of the above approach
2char
2 // C++ implementation of the above approach
35char
namespace
05
// C++ implementation of the above approach
2// C++ implementation of the above approach
1
using
0
using
0// C++ implementation of the above approach
42
using
0// C++ implementation of the above approach
44
using
0namespace
6 namespace
7namespace
8 namespace
17
using
0// C++ implementation of the above approach
1
std;
7char
namespace
22char
namespace
24
std;
7
std;
7std;
1
std;
7std;
3
std;
7// C++ implementation of the above approach
7 std;
6
// C++ implementation of the above approach
71std;
8
std;
7// C++ implementation of the above approach
1
// C++ implementation of the above approach
71
// C++ implementation of the above approach
71// Function to check if a character is a vowel
0
_______071____081
_______071____343
_______071____345
std;
7using
8
using
0using
8
using
0using
1 namespace
52namespace
53namespace
54
// C++ implementation of the above approach
2using
8
// C++ implementation of the above approach
2____59
________ 02 ________ 102 ________ 82 ________ 104 ________ 363
// C++ implementation of the above approach
2// C++ implementation of the above approach
1
using
0#include
09____65using
3
using
0____371
// C++ implementation of the above approach
2using
8
using
8
namespace
75
PHP
namespace
76
namespace
77
// Function to check if a character is a vowel
namespace
79 isVowel[
____381#include
9
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2______381 #include
24____387namespace
7namespace
81namespace
90
// C++ implementation of the above approach
2// C++ implementation of the above approach
7 namespace
7namespace
81 namespace
95// C++ implementation of the above approach
9 namespace
97namespace
81 namespace
95#include
1 namespace
97namespace
81 namespace
95#include
3
// C++ implementation of the above approach
71namespace
97namespace
81 namespace
95#include
6 namespace
97namespace
81 namespace
95#include
8#include
9
using
0using
1 std;
17
// C++ implementation of the above approach
2using
1 std;
20
using
8
using
9
namespace
0
namespace
79 std;
25std;
26#include
9
// C++ implementation of the above approach
1
// C++ implementation of the above approach
2____34
// C++ implementation of the above approach
2namespace
6 namespace
7std;
34 std;
35std;
34 std;
37std;
38namespace
7std;
26std;
41std;
34std;
43
using
0std;
1
using
0____43
using
0// C++ implementation of the above approach
7 std;
50std;
26std;
52std;
34std;
54std;
26std;
52std;
34 std;
58
std;
7std;
60______426std;
52std;
34std;
64std;
26std;
52std;
34 std;
68
using
0// C++ implementation of the above approach
1
std;
7// Function to check if a character is a vowel
0
std;
7std;
74 #include
24____426std;
52std;
34// C++ implementation of the above approach
85
_______47____426____452____434____484std;
26____452std;
34 std;
88
_______47____426____452____434std;
93std;
74using
3
using
0using
8
// C++ implementation of the above approach
2using
8
// C++ implementation of the above approach
2using
1 std;
26using
3
using
8
// C++ implementation of the above approach
2____59
// C++ implementation of the above approach
2______426 #include
24____65using
3
// C++ implementation of the above approach
2____513 std;
25____426namespace
90
// C++ implementation of the above approach
2using
1 isVowel[
1
// Function to check if a character is a vowel
20
// Function to check if a character is a vowel
21
Javascript
// Function to check if a character is a vowel
22
_______523____524
// Function to check if a character is a vowel
23isVowel[
8
// Function to check if a character is a vowel
23char
0
// Function to check if a character is a vowel
23namespace
79 // Function to check if a character is a vowel
31
using
0// Function to check if a character is a vowel
33
using
0// C++ implementation of the above approach
7 // Function to check if a character is a vowel
36// Function to check if a character is a vowel
37 // Function to check if a character is a vowel
38// Function to check if a character is a vowel
39 // Function to check if a character is a vowel
38// Function to check if a character is a vowel
41 // Function to check if a character is a vowel
38// Function to check if a character is a vowel
43 // Function to check if a character is a vowel
38// Function to check if a character is a vowel
45// Function to check if a character is a vowel
46