UVA 11192 Solution

/*
  Name: UVA11192
  Author: zoom
  Date: 21/06/12
*/
using namespace std;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<limits>
#include<cmath>
#include<queue>
#include<map>
#define LLU long long unsigned int
#define LLD long long double
#define FOR(i,N) for(int i=0;i<(N);i++)
int main()
{
    int N, l, NoOfPieces;
    string str;
    char c;
    while(scanf("%d", &N)!=EOF)
    {
        if(N==0) // N = number of pieces
            break;
        scanf("%c", &c);
        getline(cin, str);
        NoOfPieces = str.length()/N;
        for(int i=0; i<N; i++)
        {
            l=i*NoOfPieces;
            for(int j=0; j<NoOfPieces/2; j++)
            {
                c = str[l+j];
                str[l+j] = str[l + NoOfPieces - 1 - j];
                str[l + NoOfPieces - 1 - j] = c;
            }
        }
        cout<<str<<endl;
    }
    return 0;
}

UVA 10323 Solution

/*
  Name: UVA10323
  Author: zoom
  Date: 23/04/11
*/
using namespace std;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<limits>
#include<cmath>
#include<queue>
#include<map>
#define LLU long long unsigned int
#define LLD long long double
#define FOR(i,N) for(int i=0;i<(N);i++)
int main()
{
    long long n;
    vector<LLU> fib;
    fib.push_back(1);
    fib.push_back(1);
    for(int i = 2; i < 14; i++)
    {
        fib.push_back(fib[i-1] * i);
    }
    while(scanf(“%lld”, &n)!=EOF)
    {
        if(n < 0)
        {
            if( n / 2 * 2 == n)
                printf(“Underflow!\n”);
            else
                printf(“Overflow!\n”);
        }
        else if(n<8)
        {
            cout<<“Underflow!\n”;
        }
        else if(n>13)
        {
            cout<<“Overflow!\n”;
        }
        else
        {
            cout<<fib[n]<<endl;
        }
    }
}

UVA 621 Solution

/*
  Name: UVA621
  Author: zoom
  Date: 31/07/11
*/
using namespace std;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<limits>
#include<cmath>
#include<queue>
#include<map>
#define LLU long long unsigned int
#define LLD long long double
#define FOR(i,N) for(int i=0;i<(N);i++)
int main()
{
    string str;
    int Length,N;
    scanf(“%d\n”,&N);
    while(N–)
    {
        getline(cin,str);
        Length=str.length();
        if(str==”1″ || str==”4″ || str==”78″)
        printf(“+\n”);
        else if(Length>=2 and str[Length-1]==’5′ and str[Length-2]==’3′)
        printf(“-\n”);
        else if(str[0]==’9′ and str[Length-1]==’4′)
        printf(“*\n”);
        else if(Length>=3 and str[0]==’1′ and str[1]==’9′ and str[2]==’0′)
        printf(“?\n”);
    }
}

UVA 573 Solution

/*
  Name:  UVA573
  Author: zoom
  Date: 31/07/11
*/
using namespace std;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<limits>
#include<cmath>
#include<queue>
#include<map>
#define LLU long long unsigned int
#define LLD long long double
#define FOR(i,N) for(int i=0;i<(N);i++)
int main()
{
    int H,U,D,F;
    while(cin>>H>>U>>D>>F and (H||D||U||F))
    {
        bool success=false;
        int day=1;
        double UF=U,Height=0.0F,FF=UF*F/100.0;
        while(true)
        {
            if(UF>0)
            Height+=UF;
            if(Height>H)
            {
                success=true;
                break;
            }
            Height-=D;
            if(Height<0) break;
            UF-=FF;
//            cout<<“day=”<<day<<” “<<Height<<” “<<UF<<” “<<D<<“\n”;
            day++;
        }
        if(success) cout<<“success on day “<<day<<endl;
        else cout<<“failure on day “<<day<<endl;
    }
}