nyoj 803-A/B Problem

803-A/B Problem


内存限制:64MB 时间限制:1000ms 特判: No
通过数:2 提交数:4 难度:3

题目描述:

 做了A+B Problem,A/B Problem不是什么问题了吧!

输入描述:

每组测试样例一行,首先一个号码A,中间一个或多个空格,然后一个符号( / 或者 % ),然后又是空格,后面又是一个号码B,A可能会很长,B是一个int范围的数。

输出描述:

输出结果。

样例输入:

110 / 100
99 % 10
2147483647 / 2147483647
2147483646 % 2147483647

样例输出:

1
9
1
2147483646

python   未AC:

try:
    while True:
        a, b, c = input().split()
        a = int(a)
        c = int(c)

        if b == "/":
            print("%d" % (a / c))
        else:
            print("%d" % (a % c))
except EOFError:
    pass

C/C++ AC:(引之runbicheng)

#include<stdio.h>
#include<string.h>
char str[1000],ch[5];
int main()
{
    int b,s,i,n,f;
    while(~scanf("%s%s%d",str,&ch,&b))
    {
        s=i=0,f=0;
        n = strlen(str);
        if(*ch=='%')
        {
            for(i=0; i<n; i++)
            {
                s=s*10+str[i]-48;
                s%=b;
            }
            printf("%d\n",s);
        }
        else
        {
            for(i=0; i<n; i++)
            {
                s=s*10+str[i]-48;
                if(s>=b)
                {
                    printf("%d",s/b);
                    f=1;
                }
                else if(f)
                {
                    putchar(48);
                }
                s%=b;
            }
            printf(!f?"0\n":"\n");
        }
    }
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/GetcharZp/p/9354033.html
今日推荐