Skip to main content

Remove consecutive alphabets which are in same type

Here given code implementation process.

/*
    Java Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
public class RemoveCharacters
{
	public boolean isDiffernt(char x, char y)
	{
		if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
            ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	public void removeSameType(String text)
	{
		// Get the length
		int n = text.length();
		if (n == 0)
		{
			return;
		}
		String result = "" + text.charAt(0);
		char v = text.charAt(0);
		for (int i = 1; i < n; ++i)
		{
			if (isDiffernt(v, text.charAt(i)) == true)
			{
				result = result + text.charAt(i);
			}
			// Get current character
			v = text.charAt(i);
		}
		System.out.println(" Given text : " + text);
		System.out.println(" Result     : " + result);
	}
	public static void main(String[] args)
	{
		RemoveCharacters task = new RemoveCharacters();
		// Test
		task.removeSameType("mfStHDrr");
		task.removeSameType("AxccBsDDdcTATM");
	}
}

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
// Include header file
#include <iostream>
#include <string>

using namespace std;
/*
    C++ Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
class RemoveCharacters
{
    public: bool isDiffernt(char x, char y)
    {
        if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
            ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')))
        {
            // When x and y is differnt type
            return true;
        }
        // When x and y are same type
        return false;
    }
    void removeSameType(string text)
    {
        // Get the length
        int n = text.length();
        if (n == 0)
        {
            return;
        }
        string result = "";
        result += text[0];
        char v = text[0];
        for (int i = 1; i < n; ++i)
        {
            if (this->isDiffernt(v, text[i]) == true)
            {
                result = result  +  (text[i]);
            }
            // Get current character
            v = text[i];
        }
        cout << " Given text : " << text << endl;
        cout << " Result     : " << result << endl;
    }
};
int main()
{
    RemoveCharacters *task = new RemoveCharacters();
    // Test
    task->removeSameType("mfStHDrr");
    task->removeSameType("AxccBsDDdcTATM");
    return 0;
}

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
package main
import "fmt"
/*
    Go Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
type RemoveCharacters struct {}
func getRemoveCharacters() * RemoveCharacters {
	var me *RemoveCharacters = &RemoveCharacters {}
	return me
}
func(this RemoveCharacters) isDiffernt(x, y byte) bool {
	if ((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
	((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')) {
		// When x and y is differnt type
		return true
	}
	// When x and y are same type
	return false
}
func(this RemoveCharacters) removeSameType(text string) {
	// Get the length
	var n int = len(text)
	if n == 0 {
		return
	}
	var result string = ""+ string(text[0])
	var v byte = text[0]
	for i := 1 ; i < n ; i++ {
		if this.isDiffernt(v, text[i]) == true {
			result = result + string(text[i])
		}
		// Get current character
		v = text[i]
	}
	fmt.Println(" Given text : ", text)
	fmt.Println(" Result     : ", result)
}
func main() {
	var task * RemoveCharacters = getRemoveCharacters()
	// Test
	task.removeSameType("mfStHDrr")
	task.removeSameType("AxccBsDDdcTATM")
}

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
// Include namespace system
using System;
/*
    Csharp Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
public class RemoveCharacters
{
	public Boolean isDiffernt(char x, char y)
	{
		if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
            ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	public void removeSameType(String text)
	{
		// Get the length
		int n = text.Length;
		if (n == 0)
		{
			return;
		}
		String result = "" + text[0];
		char v = text[0];
		for (int i = 1; i < n; ++i)
		{
			if (this.isDiffernt(v, text[i]) == true)
			{
				result = result + text[i];
			}
			// Get current character
			v = text[i];
		}
		Console.WriteLine(" Given text : " + text);
		Console.WriteLine(" Result     : " + result);
	}
	public static void Main(String[] args)
	{
		RemoveCharacters task = new RemoveCharacters();
		// Test
		task.removeSameType("mfStHDrr");
		task.removeSameType("AxccBsDDdcTATM");
	}
}

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
<?php
/*
    Php Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
class RemoveCharacters
{
	public	function isDiffernt($x, $y)
	{
		if ((($x >= 'a' && $x <= 'z') && ($y >= 'A' && $y <= 'Z')) || 
            (($x >= 'A' && $x <= 'Z') && ($y >= 'a' && $y <= 'z')))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	public	function removeSameType($text)
	{
		// Get the length
		$n = strlen($text);
		if ($n == 0)
		{
			return;
		}
		$result = "".strval($text[0]);
		$v = $text[0];
		for ($i = 1; $i < $n; ++$i)
		{
			if ($this->isDiffernt($v, $text[$i]) == true)
			{
				$result = $result.strval($text[$i]);
			}
			// Get current character
			$v = $text[$i];
		}
		echo(" Given text : ".$text.
			"\n");
		echo(" Result     : ".$result.
			"\n");
	}
}

function main()
{
	$task = new RemoveCharacters();
	// Test
	$task->removeSameType("mfStHDrr");
	$task->removeSameType("AxccBsDDdcTATM");
}
main();

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
/*
    Node JS Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
class RemoveCharacters
{
	isDiffernt(x, y)
	{
		if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
            ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	removeSameType(text)
	{
		// Get the length
		var n = text.length;
		if (n == 0)
		{
			return;
		}
		var result = "" + text.charAt(0);
		var v = text.charAt(0);
		for (var i = 1; i < n; ++i)
		{
			if (this.isDiffernt(v, text.charAt(i)) == true)
			{
				result = result + text.charAt(i);
			}
			// Get current character
			v = text.charAt(i);
		}
		console.log(" Given text : " + text);
		console.log(" Result     : " + result);
	}
}

function main()
{
	var task = new RemoveCharacters();
	// Test
	task.removeSameType("mfStHDrr");
	task.removeSameType("AxccBsDDdcTATM");
}
main();

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
#    Python 3 Program for
#    Remove consecutive alphabets which are in same type
#    small characters and capital characters
class RemoveCharacters :
	def isDiffernt(self, x, y) :
		if (((x >= 'a'
				and x <= 'z') and(y >= 'A'
				and y <= 'Z')) or((x >= 'A'
				and x <= 'Z') and(y >= 'a'
				and y <= 'z'))) :
			#  When x and y is differnt type
			return True
		
		#  When x and y are same type
		return False
	
	def removeSameType(self, text) :
		#  Get the length
		n = len(text)
		if (n == 0) :
			return
		
		result = str(text[0])
		v = text[0]
		i = 1
		while (i < n) :
			if (self.isDiffernt(v, text[i]) == True) :
				result = result + str(text[i])
			
			#  Get current character
			v = text[i]
			i += 1
		
		print(" Given text : ", text)
		print(" Result     : ", result)
	

def main() :
	task = RemoveCharacters()
	#  Test
	task.removeSameType("mfStHDrr")
	task.removeSameType("AxccBsDDdcTATM")

if __name__ == "__main__": main()

Output

 Given text :  mfStHDrr
 Result     :  mStHr
 Given text :  AxccBsDDdcTATM
 Result     :  AxBsDdT
#    Ruby Program for
#    Remove consecutive alphabets which are in same type
#    small characters and capital characters
class RemoveCharacters 
	def isDiffernt(x, y) 
		if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
            ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z'))) 
			#  When x and y is differnt type
			return true
		end

		#  When x and y are same type
		return false
	end

	def removeSameType(text) 
		#  Get the length
		n = text.length
		if (n == 0) 
			return
		end

		result = text[0].to_s
		v = text[0]
		i = 1
		while (i < n) 
			if (self.isDiffernt(v, text[i]) == true) 
				result = result + text[i].to_s
			end

			#  Get current character
			v = text[i]
			i += 1
		end

		print(" Given text : ", text, "\n")
		print(" Result     : ", result, "\n")
	end

end

def main() 
	task = RemoveCharacters.new()
	#  Test
	task.removeSameType("mfStHDrr")
	task.removeSameType("AxccBsDDdcTATM")
end

main()

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
import scala.collection.mutable._;
/*
    Scala Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
class RemoveCharacters()
{
	def isDiffernt(x: Char, y: Char): Boolean = {
		if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
      ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	def removeSameType(text: String): Unit = {
		// Get the length
		var n: Int = text.length();
		if (n == 0)
		{
			return;
		}
		var result: String = text.charAt(0).toString();
		var v: Char = text.charAt(0);
		var i: Int = 1;
		while (i < n)
		{
			if (isDiffernt(v, text.charAt(i)) == true)
			{
				result = result + text.charAt(i).toString();
			}
			// Get current character
			v = text.charAt(i);
			i += 1;
		}
		println(" Given text : " + text);
		println(" Result     : " + result);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: RemoveCharacters = new RemoveCharacters();
		// Test
		task.removeSameType("mfStHDrr");
		task.removeSameType("AxccBsDDdcTATM");
	}
}

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT
import Foundation;
/*
    Swift 4 Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
class RemoveCharacters
{
	func isDiffernt(_ x: Character, _ y: Character) -> Bool
	{
		if (((x >= "a" && x <= "z") && (y >= "A" && y <= "Z")) || 
            ((x >= "A" && x <= "Z") && (y >= "a" && y <= "z")))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	func removeSameType(_ data: String)
	{
        let text = Array(data);
		// Get the length
		let n: Int = text.count;
		if (n == 0)
		{
			return;
		}
		var result: String = ""
		+ String(text[0]);
		var v: Character = text[0];
		var i: Int = 1;
		while (i < n)
		{
			if (self.isDiffernt(v, text[i]) == true)
			{
				result = result + String(text[i]);
			}
			// Get current character
			v = text[i];
			i += 1;
		}
		print(" Given text : ", data);
		print(" Result     : ", result);
	}
}
func main()
{
	let task: RemoveCharacters = RemoveCharacters();
	// Test
	task.removeSameType("mfStHDrr");
	task.removeSameType("AxccBsDDdcTATM");
}
main();

Output

 Given text :  mfStHDrr
 Result     :  mStHr
 Given text :  AxccBsDDdcTATM
 Result     :  AxBsDdT
/*
    Kotlin Program for
    Remove consecutive alphabets which are in same type
    small characters and capital characters
*/
class RemoveCharacters
{
	fun isDiffernt(x: Char, y: Char): Boolean
	{
		if (((x >= 'a' && x <= 'z') && (y >= 'A' && y <= 'Z')) || 
            ((x >= 'A' && x <= 'Z') && (y >= 'a' && y <= 'z')))
		{
			// When x and y is differnt type
			return true;
		}
		// When x and y are same type
		return false;
	}
	fun removeSameType(text: String): Unit
	{
		// Get the length
		val n: Int = text.length;
		if (n == 0)
		{
			return;
		}
		var result: String = text.get(0).toString();
		var v: Char = text.get(0);
		var i: Int = 1;
		while (i < n)
		{
			if (this.isDiffernt(v, text.get(i)) == true)
			{
				result = result + text.get(i).toString();
			}
			// Get current character
			v = text.get(i);
			i += 1;
		}
		println(" Given text : " + text);
		println(" Result     : " + result);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: RemoveCharacters = RemoveCharacters();
	// Test
	task.removeSameType("mfStHDrr");
	task.removeSameType("AxccBsDDdcTATM");
}

Output

 Given text : mfStHDrr
 Result     : mStHr
 Given text : AxccBsDDdcTATM
 Result     : AxBsDdT




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment