原文:
给定一个字符串 s ,打印字符串的反串,并从反串中删除原字符串中有元音的字符。 例:
input : geeksforgeeks
output : segrfseg
explanation :
reversed string is skeegrofskeeg, removing characters
from indexes 1, 2, 6, 9 & 10 (0 based indexing),
we get segrfseg .
input :duck
output :kud
一个简单的解决方法就是先倒串,然后遍历倒串,去掉元音。 一个高效的pg电子试玩链接的解决方案是在一次遍历中完成两个任务。 创建一个空字符串 r,遍历原始字符串 s,并将值赋给字符串 r。检查在该索引处,原始字符串是否包含辅音。如果是,则打印字符串 r 索引处的元素 上述方法的基本实现:
c
// cpp program for removing characters
// from reversed string where vowels are
// present in original string
#include
using namespace std;
// function for replacing the string
void replaceoriginal(string s, int n)
{
// initialize a string of length n
string r(n, ' ');
// traverse through all characters of string
for (int i = 0; i < n; i ) {
// assign the value to string r
// from last index of string s
r[i] = s[n - 1 - i];
// if s[i] is a consonant then
// print r[i]
if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i'
&& s[i] != 'o' && s[i] != 'u') {
cout << r[i];
}
}
cout << endl;
}
// driver function
int main()
{
string s = "geeksforgeeks";
int n = s.length();
replaceoriginal(s, n);
return 0;
}
java 语言(一种计算机语言,尤用于创建网站)
// java program for removing characters
// from reversed string where vowels are
// present in original string
class gfg {
// function for replacing the string
static void replaceoriginal(string s, int n) {
// initialize a string of length n
char r[] = new char[n];
// traverse through all characters of string
for (int i = 0; i < n; i ) {
// assign the value to string r
// from last index of string s
r[i] = s.charat(n - 1 - i);
// if s[i] is a consonant then
// print r[i]
if (s.charat(i) != 'a' && s.charat(i) != 'e' && s.charat(i) != 'i'
&& s.charat(i) != 'o' && s.charat(i) != 'u') {
system.out.print(r[i]);
}
}
system.out.println("");
}
// driver function
public static void main(string[] args) {
string s = "geeksforgeeks";
int n = s.length();
replaceoriginal(s, n);
}
}
// this code is contributed by princiraj1992
python 3
# python3 program for removing characters
# from reversed string where vowels are
# present in original string
# function for replacing the string
def replaceoriginal(s, n):
# initialize a string of length n
r = [' '] * n
# traverse through all characters of string
for i in range(n):
# assign the value to string r
# from last index of string s
r[i] = s[n - 1 - i]
# if s[i] is a consonant then
# print r[i]
if (s[i] != 'a' and s[i] != 'e' and
s[i] != 'i' and s[i] != 'o' and
s[i] != 'u'):
print(r[i], end = "")
print()
# driver code
if __name__ == "__main__":
s = "geeksforgeeks"
n = len(s)
replaceoriginal(s, n)
# this code is contributed by
# sanjeev2552
c
// c# program for removing characters
// from reversed string where vowels are
// present in original string
using system;
class gfg
{
// function for replacing the string
static void replaceoriginal(string s, int n)
{
// initialize a string of length n
char []r = new char[n];
// traverse through all characters of string
for (int i = 0; i < n; i )
{
// assign the value to string r
// from last index of string s
r[i] = s[n - 1 - i];
// if s[i] is a consonant then
// print r[i]
if (s[i] != 'a' && s[i] != 'e' && s[i] != 'i'
&& s[i] != 'o' && s[i] != 'u')
{
console.write(r[i]);
}
}
console.writeline("");
}
// driver code
public static void main(string[] args)
{
string s = "geeksforgeeks";
int n = s.length;
replaceoriginal(s, n);
}
}
// this code is contributed by rajput-ji
java 描述语言
输出:
segrfseg
麻将胡了pg电子网站的版权属于:月萌api www.moonapi.com,转载请注明出处