zoukankan      html  css  js  c++  java
  • 杭电2099 整除的尾数

    整除的尾数

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 40634    Accepted Submission(s): 17370


    Problem Description
    一个整数,只知道前几位,不知道末二位,被另一个整数除尽了,那么该数的末二位该是什么呢?
     
    Input
    输入数据有若干组,每组数据包含二个整数a,b(0<a<10000, 10<b<100),若遇到0 0则处理结束。
     
    Output
    对应每组数据,将满足条件的所有尾数在一行内输出,格式见样本输出。同组数据的输出,其每个尾数之间空一格,行末没有空格。
     
    Sample Input
    200 40 1992 95 0 0
     
    Sample Output
    00 40 80 15
     

     其实这样的题目就是一个纸老虎,我开始是一点都摸不着头脑,然后偷懒去百度了一下,看到一个思路:一个数的末尾两位无非就是00~99,所以,我们直接就给这个数*100+0~99之后再去除我们输入的另一个数,这样如果取余后==0,那么就是可以整除,我们把这个数给输出即可。

    注意一:就是我们最后的输出是不允许有“ ”空格的,所以,我们选择把空格加在前面,就是第一个数正常输出,第二个数的前面加空格。

    注意二:要是输出的数是小于10的话,要在前面+0;

    综上 附上代码:

     1 #include <iostream>
     2 #include<math.h>
     3 #include <iomanip>
     4 #include<cstdio>
     5 #include<string>
     6 #include<map>
     7 #include<vector>
     8 #include<list>
     9 #include<algorithm>
    10 #include<stdlib.h>
    11 #include<iterator>
    12 #include<sstream>
    13 #include<string.h>
    14 using namespace std;
    15 
    16 int main()
    17 {
    18    int m,n;
    19    while(cin>>m>>n)
    20    {
    21        if(m==0&&n==0)
    22        {
    23            break;
    24        }
    25        int temp;
    26        int flag=0;
    27 
    28        for(int i=0;i<=99;i++)//后面的数无非是0~99
    29        {
    30            temp=m*100+i;
    31 
    32            if(temp%n==0)
    33            {
    34                flag++;
    35                if(flag==1)//flag用来判断是不是 第一个数 这个是第一个的情况
    36                {
    37                    if(i<10)
    38                    {
    39                        cout<<"0"<<i;
    40                    }
    41                    else
    42                    {
    43                        cout<<i;
    44                    }
    45 
    46                }
    47                else//如果不是第一个的情况的话就要 在前面加个空格。
    48                {
    49                    if(i<10)
    50                    {
    51                        cout<<" 0"<<i;//
    52                    }
    53                    else
    54                    {
    55                        cout<<" "<<i;
    56                    }
    57                }
    58            }
    59 
    60        }
    61        cout<<endl;
    62    }
    63     return 0;
    64 }
  • 相关阅读:
    vim lua对齐indent无效
    C中的私有成员
    Lua 设置table为只读属性
    c语言结构体可以直接赋值
    Lua5.3 注册表 _G _ENV
    火狐浏览器调试ajax异步页面时报错NS_ERROR_UNEXPECTER
    ajax向后台请求数据,后台接收到数据并进行了处理,但前台就是调用error方法
    maven安装之后,或者升级之后遇到的问题:could not find or load main class org.codehaus.plexus.class.....
    jenkins执行shell命令,有时会提示“Command not found”
    shell 脚本替换文件中某个字符串
  • 原文地址:https://www.cnblogs.com/William-xh/p/7003425.html
Copyright © 2011-2022 走看看