Tags » Strings

Hackerrank : Mars Exploration

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;


int main(){
    string S;
    cin >> S;
    int ans = 0;
    for(int i=0;i<S.size();i+=3){
        string temp = S.substr(i,3);
        if(temp[0] != 'S') ans++;
        if(temp[1] != 'O') ans++;
        if(temp[2] != 'S') ans++;
    }
    printf("%d",ans);
    return 0;
}
Data Structures

Hackerrank : Beautiful Binary String

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <cassert>
#include <algorithm>
#include <unordered_map>
#define BLACK 1
#define WHITE 0

using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    ll ans=0;
    for(ll i=0;i<n-2;i++){
        string temp;
        temp=s.substr(i,3);
        if(temp == "010"){
            s = '1';
            ans++;
        }
    }
    cout<<ans;
    return 0;
}
Data Structures

Hackerrank : Super Reduced String

/*
*   Stack Application !!
*/
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;


int main() { 
    vector <char> s;
    char temp;
    while(scanf("%c",&temp)==1){
        if(s.empty()) s.push_back(temp);
        else {
            if(s == temp) s.pop_back();
            else s.push_back(temp);
        }
    }
    if(s.empty()) printf("Empty String\n");
    else {
        for(int i=0;i<s.size();i++) printf("%c",s[i]);
    }
    return 0;
}
Data Structures

Fidelity - dVerse

Artist: Claudia Schoenfeld

He holds his guitar as a lover,
Stroking the maple, the cherrywood,
And most of all, the singing strings.

His sleep is filled with chords, 151 more words

Creative Writing

A Long Journey

Bless you all with pleasant journeys filled with love and adventure!

Daily Tidbits