zoukankan      html  css  js  c++  java
  • HDU——1405The Last Practice(试手map)

    The Last Practice

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 9185    Accepted Submission(s): 1947


    Problem Description
    Tomorrow is contest day, Are you all ready?
    We have been training for 45 days, and all guys must be tired.But , you are so lucky comparing with many excellent boys who have no chance to attend the Province-Final.

    Now, your task is relaxing yourself and making the last practice. I guess that at least there are 2 problems which are easier than this problem.
    what does this problem describe?
    Give you a positive integer, please split it to some prime numbers, and you can got it through sample input and sample output.
     


     

    Input
    Input file contains multiple test case, each case consists of a positive integer n(1<n<65536), one per line. a negative terminates the input, and it should not to be processed.
     


     

    Output
    For each test case you should output its factor as sample output (prime factor must come forth ascending ), there is a blank line between outputs.
     


     

    Sample Input
    60 12 -1
     


     

    Sample Output
    Case 1. 2 2 3 1 5 1 Case 2. 2 2 3 1
    Hint
    60=2^2*3^1*5^1

    本地编译器优化的太多也不好,一个语句分号前面多了个逗号竟然也可以编译,第一次妥妥的CE了

    代码:

    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    #include<map>
    #include<set>
    using namespace std;
    int main(void)
    {
        int n,i,t=0;
        while (cin>>n&&n>=0)
        {
            t++;
            if(t!=1)
                cout<<endl;
            map<int,int> list;
            for (i=2; i<=n; i++)
            {
                while (n%i==0)
                {
                    list[i]++;
                    n/=i;
                }
            }
            map<int,int>::iterator it;
            printf("Case %d.
    ",t);
            for (it=list.begin(); it!=list.end(); it++)
            {
                    cout<<it->first<<" "<<it->second<<" ";//这题有毒竟然不按套路出牌,最后也要有空格
            }
            cout<<endl;
        }
        return 0;
    }
  • 相关阅读:
    同步、异步 与 阻塞、非阻塞
    【转】综合对比 Kafka、RabbitMQ、RocketMQ、ActiveMQ 四个分布式消息队列
    Kafka总结笔记
    SpringBoot笔记
    过滤器(Filter)和拦截器(Interceptor)的执行顺序和区别
    Java Lambda表达式
    腾讯云博客同步声明(非技术文)
    SpringBoot学习笔记(十七:异步调用)
    设计模式—— 十七:装饰器模式
    Java初级开发0608面试
  • 原文地址:https://www.cnblogs.com/Blackops/p/5356431.html
Copyright © 2011-2022 走看看