zoukankan      html  css  js  c++  java
  • 南邮NOJ整除的尾数

    整除的尾数

    时间限制(普通/Java) : 1000 MS/ 3000 MS          运行内存限制 : 32768 KByte
    总提交 : 346            测试通过 : 145 

    题目描述

    一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢?

    输入

    输入数据有若干组,每组数据包含二个整数a,b(0<a<10000, 10<b<100),若遇到0 0则处理结束。

    输出

    对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。

    样例输入

    200 40
    1992 95
    0 0

    样例输出

    00 40 80
    15

    #include <iostream>
    #include<cstdio>
    using namespace std;
    
    int main()
    {
        int a,b;
        while(scanf("%d%d",&a,&b)==2&&a!=0&&b!=0)
        {
            int c=a*100,p=0;
            for(int i=0;i<=99;i++)
            {
                if((c+i)%b==0&&i>=0&&i<=9)
                {
                    p=1;
                    cout<<"0"<<i;
                }
                if((c+i)%b==0&&i>=10)
                {
                    if(p==1)
                     printf(" %d",i);
                     else
                     {
                        printf("%d",i);
                        p=1;
                     }
                }
            }
            printf("
    ");
        }
        return 0;
    }

    一直WA,后来看到交流模块,有人提到输入1 34的情况,才意识到自己对00-09的情况没考虑完整。

    将输出改成cout<<"0"<<i; 就行了。


    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    【Longest Common Prefix】cpp
    【WildCard Matching】cpp
    【 Regular Expression Matching 】cpp
    【Longest Palindromic Substring】cpp
    【Add binary】cpp
    【String to Integer (atoi) 】cpp
    【Implement strStr() 】cpp
    【Valid Palindrome】cpp
    【LRU Cache】cpp
    【Reorder List】cpp
  • 原文地址:https://www.cnblogs.com/Tobyuyu/p/4965738.html
Copyright © 2011-2022 走看看