String Ignorance | Practice | GeeksforGeeks

Given a string of both uppercase and lowercase alphabets, the task is to print the string with alternate occurrences of any character dropped(including space and consider upper and lowercase as same).
Input:
First line consists of T test cases. First line of every test case consists of String S.
Output:
Single line output, print the updated string.
Constraints:
1<=T<=100
1<=|String|<=10000
Example:
Input:
2
It is a long day dear.
Geeks for geeks
Output:
It sa longdy ear.
Geks fore
Explanation:
For the 1st test case. 
Print first "I" and then ignore next "i". Similarly print first space then ignore next space. and so on.
0
adityagagtiwari3 weeks ago
Easy solution using HashSets
static String findans(String si){
   HashSet<Character> map = new HashSet<>();
   String result = "";
   for(char ch:si.toCharArray())
   {
       //ch = Character.toLowerCase(ch);
       //handling spaces separately
       if(ch==' ')
       {
          if(map.contains('$'))
          {
               map.remove('$');
          }
          else
          {
              result+=ch;
              map.add('$');
          }
       }
       else 
       {
           //be it lowercase or upper case the element should be pushed in both ways 
           //to satisfy the incoming criteria for next same element with a different case
           if(map.contains(ch))
           {
           
               map.remove(Character.toUpperCase(ch));
               map.remove(Character.toLowerCase(ch));
           }
           else
           {
               result+=ch;
               map.add(Character.toUpperCase(ch));
               map.add(Character.toLowerCase(ch));
               
           }
       }
   }
   return result;
}
0
ritikj12 months ago
T=int(input())
for i in range(T):
    s=input()
    a=[]
    s1=""
    for j in s:
        if j.lower() not in a:
            a.append(j.lower())
            s1=s1+j
        else:a.remove(j.lower())
    print(s1)
0
ritikj1
This comment was deleted.
0
kumarsaket6705 months ago
import java.util.*;import java.lang.*;import java.io.*;
class GFG {public static void main (String[] args) { //code   Scanner sc = new Scanner(System.in);String a;int t = sc.nextInt();sc.nextLine();  while(t>0){    String s = sc.nextLine();    a = findans(s);    System.out.println(a);    t--;}}static String findans(String si){   String s = si;    int i = 0;    while(i < s.length()){      char ch = s.charAt(i);      int first = s.indexOf(ch);           int second1 = s.indexOf(String.valueOf(ch).toLowerCase(), i + 1);        int second2 = s.indexOf(String.valueOf(ch).toUpperCase(), i + 1);        int sec;        if(second2 == -1 && second1 == -1){            sec = -1;        }else if(second2 == -1 && second1 != -1){            sec = second1;        }else if(second1 == -1 && second2 != -1){            sec = second2;        }else{            sec = second1>=second2?second2:second1;        }                    if(sec>=0){       s = charRemoveAt(s,sec);       }          i++;    }    return s;} public static String charRemoveAt(String str, int p) {               return str.substring(0, p) + str.substring(p + 1);            }  }
0
e20040805 months ago
runtime: 0.2/3.2
for _ in range(int(input())):
    s = input()
    S = ''
    arr = []
    for c in s:
        flag = True
        for i in range(len(arr)):
            if c.lower() == arr[i]:
                del arr[i]
                flag = False
                break
        if flag:
            arr += [c.lower()]
            S = S + c
    print(S)
+5
badgujarsachin835 months ago
#include<iostream>
using namespace std;
string help(string s){
    string res="";
    int arr[256]={0};
    for(int i=0;i<s.size();i++){
        arr[tolower(s[i])]++;
        if(arr[tolower(s[i])]%2!=0){
            res+=s[i];
        }
    }
    return res;
}
int main()
 {
	//code
	int t;
	cin>>t;
	cin.ignore();
	while(t--){
	    string s;
	    getline(cin,s);
	    cout<<help(s)<<endl;
	}
	return 0;
}
-2
rohitpendse1386 months ago
#include <bits/stdc++.h>

#define int long long
using namespace std;

string solve(string &s) {
    unordered_map<char, int> mp;
    string ans;
    for (int i = 0; i < s.length(); i++) {
        char temp = tolower(s[i]);
        mp[temp]++;
        if (mp[temp] & 1) ans += s[i];
    }
    return ans;
}

int32_t main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    cin.ignore();
    while (t--) {
        string s;
        getline(cin, s);
        cout << solve(s) << '\n';
    }
    return 0;
}
-1
gjayanta2367 months ago
how to implement the code?
0
Imran Wahid8 months ago
Imran Wahid
Easy C++ solution https://uploads.disquscdn.c...
0
vivek kumar10 months ago
vivek kumar
#include <bits stdc++.h="">using namespace std;int main() {    int t;    cin>>t;    cin.ignore();    while(t--)    {        string str;        getline(cin,str);        unordered_map<int,int> m;        string res="";          for(int i=0;i<str.size();i++) {="" char="" k="tolower(str[i]);" if(m[k]="=0)" {="" res+="str[i];" m[k]="1;" }="" else="" {="" m[k]="0;" }="" }="" cout<<res<<endl;="" }="" return="" 0;="" }<="" code="">
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.