Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

总是PE,哭了,牛人帮忙看看吧

Posted by ganghelloworld at 2010-05-11 13:09:00 on Problem 1489
1,不管输入的每行末尾有无空格,我都处理了。
2,输出的每行末尾都有空格
下面是程序
#include <stdio.h>
#include <stdlib.h>
int value_char(char ch)
{
    int value;
    switch(ch)
    {
        case '|':
            value = 1;
            break;
        case 'n':
            value = 10;
            break;
        case '9':
            value = 100;
            break;
        case '8':
            value = 1000;
            break;
        case 'r':
            value = 10000;
            break;
    }
    return value;
}
int display(long long value)
{
    int i, temp, res, weight;
    char num[5] = {'|', 'n', '9', '8', 'r'};
    weight = 0;
    res = 0;
    while(value)
    {
        temp = value % 10;
        res += temp;
        for(i = 0;i < temp; i++)
        {
            printf("%c", num[weight]);
        }
        weight++;
        value /= 10;
        if(value != 0 && res != 0)
        {
            printf(" ");
            res++;
        }
    }
    return res;
}
int main()
{
    char a[60], b[60], ch;
    long long avalue, bvalue;
    int alen, blen, i, len, left, right, have, n, tag;
    while(1)
    {
        alen = blen = 0;
        avalue = bvalue = 0;
        while(1)
        {
            if(scanf("%c", &ch) != 1)
            {
                printf("\n");
                return 0;
            }
            if(ch != '\n')
                a[alen++] = ch;
            else
                break;
        }
        if(a[alen-1] != ' ') a[alen++] = ' ';
        while(1)
        {
            if(scanf("%c", &ch) != 1)
            {
                printf("\n");
                return 0;
            }
            if(ch != '\n')
                b[blen++] = ch;
            else
                break;
        }
        if(b[blen-1] != ' ') b[blen++] = ' ';
        len = 0;
        for(i = 0; i < alen; i++)
        {
            if(a[i] == ' ')
            {
                avalue += len * value_char(a[i-1]);
                len = 0;
            }
            else len++;
        }
        len = 0;
        for(i = 0; i < blen; i++)
        {
            if(b[i] == ' ')
            {
                bvalue += len * value_char(b[i-1]);
                len = 0;
            }
            else len++;
        }
        left = 1;
        right = avalue;
        tag = bvalue;
        while(tag)
        {
            have = tag % 2;
            n = display(left % 100000);
            if(have)
            {
                printf(" *");
                n = n + 2;
            }
            for(i = 0; i < 34 - n; i++) printf(" ");
            display(right % 100000);
            printf(" \n");
            tag = tag >> 1;
            left = left << 1;
            right = right << 1;
        }
        if(avalue != 0 && bvalue != 0)
        {
            printf("The solution is: ");
            display((avalue * bvalue) % 100000);
            printf(" \n");
        }
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator