UVa : 12555 (B[a]by Me)


Critical Cases:

input:
4
1斤1两
10斤9两
5斤5两
6斤6两

output:
Case 1: 0.55
Case 2: 5.45
Case 3: 2.75
Case 4: 3.3


// http://uva.onlinejudge.org/external/125/12555.html
// Runtime: 0.008
// Tag: string

// @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>
#include <ctime>

#define Inf 2147483647
#define Pi acos(-1.0)
#define N 1000000
#define LL long long

inline LL Power(int b, int p) { LL ret = 1; for ( int i = 1; i <= p; i++ ) ret *= b; return ret; }

#define F(i, a, b) for( int i = (a); i < (b); i++ )
#define Fs(i, sz) for( size_t i = 0; i < sz.size (); i++ )
#define Fe(i, x) for(typeof (x.begin()) i = x.begin(); i != x.end (); i++)
#define Set(a, s) memset(a, s, sizeof (a))
#define max(a, b)  (a < b ? b : a)
#define min(a, b)  (a > b ? b : a)

using namespace std;


int main ()
{
    //freopen("inp.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);

    int testCases; scanf ("%d", &testCases);
    int cases = 0;

    while ( testCases-- ) {
        char inp [20]; scanf ("%s", inp);

        int len = strlen(inp);

        int a = 0;
        int b = 0;
        char firstStr [10];
        int result = 0;

        printf ("Case %d: ", ++cases);

        sscanf(inp, "%d%s", &a, firstStr);

        bool digitFound = true;

        for ( int i = 0; i < len; i++ ) {
            if ( isdigit(inp [i]) && digitFound ) continue;
            digitFound = false;
            if ( isdigit(inp [i]) ) {
                digitFound = true;
                b = inp [i] - '0';
                break;
            }
        }

        result = a * 50;
        result += b * 5;

        printf ("%d", result / 100);

        result %= 100;

        if ( result ) {
            if ( result % 10 == 0 ) printf (".%d", result / 10);
            else printf (".%d", result);
        }

        printf ("\n");
    }

	return 0;
}

// @END_OF_SOURCE_CODE

Advertisements

One thought on “UVa : 12555 (B[a]by Me)

  1. What’s the problem of my solution of UVa : 12555 (B[a]by Me)? my solution get wrong answer. Please help me…
    Here is my solution:
    #include
    #include

    int main()
    {
    int t, i, len, a, b;
    char string[5];

    scanf(“%d”,&t);
    for(i=1; i<=t; i++)
    {
    scanf("%s",string);
    len=strlen(string);
    if(len<=3)
    {
    if(len==3)
    {
    a=10;
    }
    else
    {
    a=string[0]-48;
    }
    b=0;
    }
    else
    {
    if(len==5)
    {
    a=10;
    b=string[3]-48;
    }
    else
    {
    a=string[0]-48;
    b=string[2]-48;
    }
    }
    printf("Case %d: ",i);
    if(b)
    {
    if(b%2==0)
    printf("%.1f\n",(float(a)*0.5+float(b)*0.05));
    else
    printf("%.2f\n",(float(a)*0.5+float(b)*0.05));
    }
    else
    {
    if(a%2==0)
    printf("%.0f\n",(float(a)*0.5));
    else
    printf("%.1f\n",(float(a)*0.5));
    }
    }

    return 0;
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s