Program Discussion :: Strings
/ 60
Write a program to remove duplicates from a given string
Answer:
#include
#include
int main()
{
char str[] = "qqq44inttttervvviieewwww......commm";
removeDuplicate(str);
printf("%s",str);
return 0;
}
void removeDuplicate (char *str)
{
char hash[256] = {0};
int x=0, y = 0;
char temp;
while (*(str+y) != '\0')
{
temp = *(str+y);
if (hash[temp] == 0)
{
hash[temp]=1;
*(str+x) = *(str+y);
x++;
}
y++;
}
*(str+x)='\0';
}
Asked In ::
Language:
Suresh
31 Mar, 2018 9:55 PM
#include <stdio.h>
#include <string.h>
int main()
{
char str[] = "qqq44inttttervvviieewwww......commm";
removeDuplicate(str);
printf("%s",str);
return 0;
}
void removeDuplicate (char *str)
{
char hash[256] = {0};
int x=0, y = 0;
char temp;
while (*(str+y) != '\0')
{
temp = *(str+y);
if (hash[temp] == 0)
{
hash[temp]=1;
*(str+x) = *(str+y);
x++;
}
y++;
}
*(str+x)='\0';
}
Language:
Qwerty
28 Sep, 2019 9:53 PM
public class strings {
public static void main(String[] args) {
String str,text1=" ";int s=0,c=0;
System.out.println("Enter The String: ");
Scanner sc=new Scanner(System.in);
String input=sc.nextLine();
String result = "";
for (int i = 0; i < input.length(); i ) {
if(!result.contains(String.valueOf(input.charAt(i)))) {
result = String.valueOf(input.charAt(i));
}
}
System.out.print(result);
}
}