Monday, December 09, 2013

[UVa] 12718 - Dromicpalin Substrings

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

bool isOdd(int val) {
    if (val & 1) return true; // bitwise checking
    else return false;
}
int counts[1000]; // only 'a' - 'z' is significant
int main( ) {

    //freopen("j.input.txt","r",stdin);
    //freopen("j.analysis.txt","w",stdout);

    int test, kase=1;
    string inputstr;

    cin >> test;

    while (test--) {

        cin >> inputstr;

        int palindromes=0;
        for (int i = 0 ; i<inputstr.size() ; i++) {
            for (int ii = 'a' ; ii<='z' ; ii++) counts[ii] = 0;
            int odds = 0;
            for (int j=i ; j<inputstr.size() ; j++) {
                counts[inputstr[j]]++;

                if ( isOdd(counts[inputstr[j]]) ) odds++;
                else odds--;
                int rangeLength = j-i+1;
                if ( isOdd(rangeLength) && odds==1 ) palindromes++;
                if ( !isOdd(rangeLength) && odds==0 ) palindromes++;
            }
        }
        cout << "Case " << kase++ << ": " << palindromes << endl;
    }

    return 0;
}


[UVa] 12712 - Pattern Locker

#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

#define MOD 10000000000007

typedef long long lint;

int main() {

    lint test, l, m, n, kase=1;

    cin >> test;

    while (test--) {

        cin >> l >> m >> n;
        lint init = 1;
        for (lint i = l*l ; i>(l*l-m) ; i--) {
            init = ((init * i)%MOD);
        }
        lint sum = init;
        for (lint i = (l*l-m) ; i>(l*l-n) ; i--) {
            init = ((init * i)%MOD);
            sum = ((sum + init)%MOD);
        }

        cout << "Case " << kase++ << ": " << sum << endl;


    }


    return 0;
}


Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...