Wednesday, July 2, 2014

UVa - 10082 - WERTYU

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
int main(){
    char s[10015];
    int i;
    while(gets(s)){
        for(i = 0; s[i]; i++){
            if(s[i] == '1')printf("`");
            if(s[i] == '2')printf("1");
            if(s[i] == '3')printf("2");
            if(s[i] == '4')printf("3");
            if(s[i] == '5')printf("4");
            if(s[i] == '6')printf("5");
            if(s[i] == '7')printf("6");
            if(s[i] == '8')printf("7");
            if(s[i] == '9')printf("8");
            if(s[i] == '0')printf("9");
            if(s[i] == '-')printf("0");
            if(s[i] == '=')printf("-");
            if(s[i] == '\\')printf("]");
            if(s[i] == ' ')printf(" ");
            if(s[i] == 'W')printf("Q");
            if(s[i] == 'E')printf("W");
            if(s[i] == 'R')printf("E");
            if(s[i] == 'T')printf("R");
            if(s[i] == 'Y')printf("T");
            if(s[i] == 'U')printf("Y");
            if(s[i] == 'I')printf("U");
            if(s[i] == 'O')printf("I");
            if(s[i] == 'P')printf("O");
            if(s[i] == '[')printf("P");
            if(s[i] == ']')printf("[");
            if(s[i] == 'S')printf("A");
            if(s[i] == 'D')printf("S");
            if(s[i] == 'F')printf("D");
            if(s[i] == 'G')printf("F");
            if(s[i] == 'H')printf("G");
            if(s[i] == 'J')printf("H");
            if(s[i] == 'K')printf("J");
            if(s[i] == 'L')printf("K");
            if(s[i] == ';')printf("L");
            if(s[i] == '\'')printf(";");
            if(s[i] == 'X')printf("Z");
            if(s[i] == 'C')printf("X");
            if(s[i] == 'V')printf("C");
            if(s[i] == 'B')printf("V");
            if(s[i] == 'N')printf("B");
            if(s[i] == 'M')printf("N");
            if(s[i] == ',')printf("M");
            if(s[i] == '.')printf(",");
            if(s[i] == '/')printf(".");
        }
        printf("\n");
    }
    return 0;
}

UVa - 10071 - Back to High School Physics

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int x, y;
    while(cin >> x >> y){
        cout << 2 * x * y << endl;
    }
    return 0;
}

UVa - 10055 - Hashmat the Brave Warrior

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    long long x, y, ans;
    while(cin >> x >> y){
       ans = abs(x - y);
        cout << ans << endl;
    }
    return 0;
}

UVa - 10038 - Jolly Jumpers

#include <iostream>
#include <cstdio>
#include <algorithm>
#define mx 3050
using namespace std;
int main(){
    int n, c, b[mx], a[mx], i;
    while(scanf("%d", &n) == 1){
        c = 1;
    for(i = 0; i < n; i++){
            scanf("%d", &a[i]);
    }
    for(i = 0; i < n - 1; i++){
            b[i] = abs(a[i + 1] - a[i]);
    }
    sort(b, b+i);
    for(i = 1; i < n; i++){
        if(b[i] == b[i - 1]){
            c = 0; break;
    }
    }
    if(c == 0)
        printf("Not jolly\n");
    else
        printf("Jolly\n");
    }
return 0;
}

UVa - 1225 - Digit Counting

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main (){
    int t, i, n, r, count[10];
    cin >> t;
    while(t--){
        cin >> n;
        memset (count, 0, sizeof count);
        for (i = 1; i <= n; i++ ){
            r = i;
            while(r > 0) {
                count [r % 10]++;
                r = r / 10;
            }
        }
        for (i = 0; i < 9; i++ ){
            cout << count[i] << " ";
        }
        cout << count[9] << endl;
    }
    return 0;
}

UVa - 694 - The Collatz Sequence

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long collatz(long long n, long long limit){
    if(n > limit)return 0;
    if(n == 1)return 1;
    if(n % 2 == 0)return 1 + collatz(n / 2, limit);
    else return 1 + collatz(3 * n + 1, limit);
}
int main(){
    long long n, L, i;
    long long c = 1;
    while(cin >> n >> L){
        if(n < 0 && L < 0)break;
        i = collatz(n, L);
        cout << "Case " << c << ": A = " << n << ", limit = " << L;
        cout << ", number of terms = " << i << endl;
        c++;
    }
    return 0;
}

UVa - 575 - Skew Binary

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
int main(){
    long int n, i, sum, num, b;
    char s[100];
    while(gets(s)){
            sum = 0;
            n = strlen(s);
            for(i = 0; i < n; i++){
                    num = s[i] - '0';
                    b = num * (pow(2, n - i) - 1);
                    sum = sum + b;
                    }
                    if(sum == 0)break;
                    printf("%ld\n", sum);
                    }
                    return 0;
                    }