Skip to content

Commit b68d719

Browse files
committed
Practice 08-Apr-2020
1 parent bddf7cb commit b68d719

8 files changed

+257
-0
lines changed

string/decode_string.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void decodeCode(string code, string enc){
5+
char arr[26];
6+
for(int i=0;i<26;i++){
7+
arr[(code[i]-'a')%26]=char(i+'a');
8+
}
9+
int n=enc.length();
10+
for(int i=0;i<n;i++){
11+
cout<<arr[enc[i]-'a'];
12+
}
13+
cout<<endl;
14+
}
15+
16+
int main()
17+
{
18+
ios_base::sync_with_stdio(false);
19+
cin.tie(NULL);
20+
int t;
21+
cin>>t;
22+
cin>>ws; //flush
23+
while(t--){
24+
string code, enc;
25+
cin>>code>>enc;
26+
decodeCode(code, enc);
27+
28+
}
29+
30+
31+
return 0;
32+
}

string/extra_char_in_string.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void extraChar(string s1, string s2){
5+
int tmp=0;
6+
int n=s1.length();
7+
for(int i=0;i<n;i++)
8+
tmp^=s1[i];
9+
n=s2.length();
10+
for(int i=0;i<n;i++)
11+
tmp^=s2[i];
12+
cout<<char(tmp)<<endl;
13+
14+
}
15+
16+
int main()
17+
{
18+
ios_base::sync_with_stdio(false);
19+
cin.tie(NULL);
20+
int t;
21+
cin>>t;
22+
cin>>ws; //flush
23+
while(t--){
24+
string s1, s2;
25+
cin>>s1>>s2;
26+
extraChar(s1, s2);
27+
}
28+
29+
30+
return 0;
31+
}

string/integer_or_string_check.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main()
5+
{
6+
ios_base::sync_with_stdio(false);
7+
cin.tie(NULL);
8+
int t;
9+
cin>>t;
10+
cin.ignore(numeric_limits<streamsize>::max(), '\n');
11+
while(t--){
12+
string s;
13+
cin>>s;
14+
bool isString =false;
15+
int n=s.length();
16+
for(int i=0;i<n;i++){
17+
int ch=s[i]-'0';
18+
if(!(ch>=0 && ch<=9)) { isString= true; break;}
19+
}
20+
if(isString) cout<<"Is a string\n";
21+
else cout<<"Not a string\n";
22+
}
23+
return 0;
24+
}

string/isZero.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
5+
bool isZero(string s){
6+
if(s[0]-'0'==0) return false;
7+
int n=s.length();
8+
for(int i=0;i<n;i++){
9+
if(s[i]-'0'==0) return true;
10+
}
11+
return false;
12+
}
13+
14+
int main(){
15+
ios_base::sync_with_stdio(false);
16+
cin.tie(NULL);
17+
cout.tie(NULL);
18+
int t;
19+
cin>>t;
20+
cin>>ws; // flush
21+
while(t--){
22+
string s;
23+
cin>>s;
24+
if(isZero(s)) cout<<"YES\n";
25+
else cout<<"NO\n";
26+
}
27+
28+
29+
30+
return 0;
31+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void missingChars(string s){
5+
bool alp[26]={false};
6+
int n=s.length();
7+
for(int i=0;i<n;i++){
8+
alp[(s[i]-'a')%26]=true;
9+
}
10+
for(int i=0;i<26;i++){
11+
if(alp[i]==false) cout<<char(i+ 97);
12+
}
13+
cout<<endl;
14+
15+
}
16+
17+
int main(){
18+
ios_base::sync_with_stdio(false);
19+
cin.tie(NULL);
20+
cout.tie(NULL);
21+
int t;
22+
cin>>t;
23+
while(t--){
24+
string s;
25+
cin>>s;
26+
missingChars(s);
27+
}
28+
return 0;
29+
}

string/pangram_check.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
bool pangramCheck(string s, int k){
5+
int cnt=0;
6+
bool alp[26]={false};
7+
int n=s.length();
8+
for(int i=0;i<n;i++){
9+
alp[(s[i]-'a')%26]=true;
10+
}
11+
for(int i=0;i<26;i++){
12+
if(alp[i]==true) cnt++;
13+
}
14+
if(n<26) return false;
15+
if(cnt+k >= 26) return true;
16+
else return false;
17+
}
18+
19+
int main(){
20+
ios_base::sync_with_stdio(false);
21+
cin.tie(NULL);
22+
cout.tie(NULL);
23+
int t;
24+
cin>>t;
25+
while(t--){
26+
string s;
27+
cin>>s;
28+
int k;
29+
cin>>k;
30+
if(pangramCheck(s, k)) cout<<"1\n";
31+
else cout<<"0\n";
32+
}
33+
34+
35+
36+
return 0;
37+
}

string/pangrammatic_lipogram.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
bool isPanLipo(string s){
5+
bool alp[26]={false};
6+
int n=s.length(), cnt=0;
7+
for(int i=0;i<n;i++){
8+
alp[(s[i]-'a')%26]=true;
9+
}
10+
for(int i=0;i<26;i++){
11+
if(alp[i]) cnt++;
12+
}
13+
if(cnt==25) return true;
14+
else return false;
15+
}
16+
17+
18+
int main(){
19+
ios_base::sync_with_stdio(false);
20+
cin.tie(NULL);
21+
cout.tie(NULL);
22+
int t;
23+
cin>>t>>ws;
24+
while(t--){
25+
string s;
26+
getline(cin, s);
27+
if(isPanLipo(s)) cout<<"YES\n";
28+
else cout<<"NO\n";
29+
}
30+
return 0;
31+
}

string/round_to_nearest_ten.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void roundToTen(string s){
5+
int n=s.length();
6+
bool carry=false;
7+
if(s[n-1]-'0'<=5) s[n-1]='0';
8+
else {
9+
for(int i=n-1;i>=0;i--){
10+
if(carry){
11+
int ch=1+s[i]-'0';
12+
if(ch>9){ ch=0; carry=true; }
13+
else carry=false;
14+
s[i]=ch+'0';
15+
if(carry==false) break;
16+
}
17+
else if(s[i]-'0'>5){ carry=true; s[i]='0'; }
18+
19+
}
20+
}
21+
if(carry) cout<<"1"<<s;
22+
else cout<<s;
23+
cout<<endl;
24+
}
25+
26+
int main()
27+
{
28+
ios_base::sync_with_stdio(false);
29+
cin.tie(NULL);
30+
int t;
31+
cin>>t;
32+
cin>>ws; //flush;
33+
while(t--){
34+
35+
string s;
36+
cin>>s;
37+
roundToTen(s);
38+
}
39+
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)