Skip to content

Commit 082078b

Browse files
committed
String Ignorance
1 parent e4bb560 commit 082078b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Some_More_Strings/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,16 @@
1616
Pattern="WTG"
1717
Output: WelcomeToGeeksForGeeks
1818
Explanation: Since only WelcomeToGeeksForGeeks matches the pattern, it is the only answer.
19+
20+
## 3. String Ignorance:
21+
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).
22+
Input: First line consists of T test cases. First line of every test case consists of String S.
23+
Output: Single line output, print the updated string.
24+
Example:
25+
Input: 2
26+
It is a long day dear.
27+
Geeks for geeks
28+
Output:
29+
It sa longdy ear.
30+
Geks fore
31+
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.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
string stringIgnorance(string str)
4+
{
5+
bool hash[256] = {0};
6+
string res;
7+
for(int i = 0 ; i < str.length() ; i++)
8+
{
9+
if(isalpha(str[i]))
10+
{
11+
if(hash[tolower(str[i])] == 0)
12+
{
13+
res += str[i];
14+
hash[tolower(str[i])] = 1;
15+
}
16+
else
17+
hash[tolower(str[i])] = 0;
18+
}
19+
else
20+
{
21+
if(hash[str[i]] == 0)
22+
{
23+
res += str[i];
24+
hash[str[i]] = 1;
25+
}
26+
else
27+
hash[str[i]] = 0;
28+
}
29+
}
30+
return res;
31+
}
32+
int main()
33+
{
34+
ios_base::sync_with_stdio(false);
35+
cin.tie(NULL);
36+
int t;
37+
cin >> t;
38+
cin.ignore();
39+
while(t--)
40+
{
41+
string str;
42+
getline(cin, str);
43+
cout << stringIgnorance(str) << endl;
44+
}
45+
return 0;
46+
}

0 commit comments

Comments
 (0)