CF: 71A (Way Too Long Words)


Problem link: http://codeforces.com/contest/71/problem/A

Solution


// @BEGIN_OF_SOURCE_CODE

#include <cstdio>
#include <cstring>

using namespace std;

int main(int argc, const char * argv[])
{
    int testCases;

    scanf ("%d", &testCases);

    char word [100 + 10];

    while ( testCases-- ) {

        scanf ("%s", word);

        int length = (int) strlen (word);

        if (length > 10) {
            printf ("%c%d%c\n", word [0], length - 2, word [length - 1]);
        } else {
            printf ("%s\n", word);
        }

    }

    return 0;
}

// @END_OF_SOURCE_CODE

CodeChef : Yet Another Number Game (NUMGAME)



// http://www.codechef.com/problems/NUMGAME/
// Runtime : 0.01s
// Memory : 2.5M
// Tag : Gotcha


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;


int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        int n;
        scanf ("%d", &n);

        if ( n % 2 ) printf ("BOB\n");
        else printf ("ALICE\n");
    }

	return 0;
}

// @END_OF_SOURCE_CODE

CodeChef : Discrepancies in the Voters List (VOTERS)



// http://www.codechef.com/problems/VOTERS/
// Runtime : 0.52s
// Tag : Sort, Merge Sort

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;


int main ()
{
	int n1, n2, n3;
	scanf ("%d %d %d", &n1, &n2, &n3);

	vector <int> v;
	int input;

	for ( int i = 0; i < n1; i++ ) {
		scanf ("%d", &input);
		v.push_back (input);
	}

	for ( int i = 0; i < n2; i++ ) {
		scanf ("%d", &input);
		v.push_back (input);
	}

	for ( int i = 0; i < n3; i++ ) {
		scanf ("%d", &input);
		v.push_back (input);
	}

	sort (v.begin (), v.end ());

	int in = 0;
	vector <int> output;

	while ( in < v.size () - 1 ) {
		if ( v [in] == v [in + 1] ) {
			output.push_back (v [in]);
			in += 2;

			if ( in != v.size () && v [in - 1] == v [in] ) in++;
		}
		else in++;
	}

	printf ("%d\n", output.size ());

	for ( int i = 0; i < output.size (); i++ ) printf ("%d\n", output [i]);


	return 0;
}

// @END_OF_SOURCE_CODE

CodeChef : Permutation Cycles (PCYCLE)



// http://www.codechef.com/problems/PCYCLE/
// Runtime : 0.00s
// Memory : 2.6M

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;

int a [1000 + 5];
bool vis [1000 + 5];
vector <int> v [1000 + 5];
int in = 0;

void traverse (int s)
{
    while ( !vis [s] ) {
        v [in].push_back (s);
        vis [s] = true;
        s = a [s];
    }

    v [in].push_back (s);
    in++;
}

int main ()
{
    int n;
    scanf ("%d", &n);

    for ( int i = 1; i <= n; i++ ) scanf ("%d", &a [i]);

    memset (vis, false, sizeof (vis));

    for ( int i = 1; i <= n; i++ ) if ( !vis [i] ) traverse (i);

    printf ("%d\n", in);

    for ( int i = 0; i < in; i++ ) {
        printf ("%d", v [i] [0]);
        for ( unsigned int j = 1; j < v [i].size (); j++ ) printf (" %d", v [i] [j]);
        printf ("\n");
    }

	return 0;
}

// @END_OF_SOURCE_CODE

CodeChef : Stone Game (RESN04)



// http://www.codechef.com/problems/RESN04/

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;


int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        int n;
        scanf ("%d", &n);

        int pile;
        int moves = 0;

        for ( int i = 0; i < n; i++ ) {
            scanf ("%d", &pile);
            moves += pile / (i + 1);
        }

        if ( moves % 2 ) printf ("ALICE\n");
        else printf ("BOB\n");
    }

	return 0;
}

// @END_OF_SOURCE_CODE

CodeChef : Odd (DCE05)



// http://www.codechef.com/problems/DCE05

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;


int main ()
{
    int testCase;
	scanf ("%d", &testCase);

	while ( testCase-- ) {
		unsigned int n;
		scanf ("%u", &n);
		for ( int i = 0; i < 32; i++ ) {
			if ( pow (2, i) > n ) {
				printf ("%d\n", (int)pow (2, i - 1));
				break;
			}
		}
	}

	return 0;
}

// @END_OF_SOURCE_CODE

CodeChef : Problem 3 (CMB03)


// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
#define LL long long
using namespace std;


int main ()
{
    int testCase;
    scanf ("%d", &testCase);

    while ( testCase-- ) {
        string a;
        string b;

        cin >> a >> b;

        if ( a.find (b) != string::npos ) printf ("1\n");
        else printf ("0\n");
    }

	return 0;
}

// @END_OF_SOURCE_CODE