首页 > ACM题库 > HDU-杭电 > hdu 1916 Hardware模拟[解题报告]C++
2013
12-30

hdu 1916 Hardware模拟[解题报告]C++

Hardware

问题描述 :

Ola Clason’s Hardware store is an old company where most work is done “the old way”. Among other things, the company is the one and only provider of marble house numbers. These house numbers have become extremely popular among construction companies, especially the ones building luxury estates. This is of course great for Ola Clason, but also a small problem. Nisse, who has been managing the incoming orders has turned out to be a bottleneck in Ola’s business. Most orders are on the form “Coconut Drive 200, 202, 204, …, 220”. This means every even number between 200 and 220. Nisse’s work is to transfer an order to a list of necessary digits and other symbols.Your assignment is to write a program that automates Nisse’s work with orders containing only positive integer house numbers. Nisse will still in the future process all special orders (those including non digit symbols) by hand.

输入:

On the first line of input is a single positive integer n, specifying the number of orders that follow. The first line of each order contains the road name for that order. No road name is longer than 50 characters. The second line states the total number of buildings needing new marble numbers on that order. Then follows the different house number specifications on several lines. These lines are of two kinds: single number lines and multiple number lines. A single number line simply consists of the house number by itself, while a multiple number line starts with a “+”-sign, followed by three positive integer numbers: first number, last number and the interval between the house numbers. The distance between the first and last house number will always be a multiple of the house number interval. A house number will never have more than five digits. After the last house number specification line, the next order follows, if there is any.

输出:

On the first line of input is a single positive integer n, specifying the number of orders that follow. The first line of each order contains the road name for that order. No road name is longer than 50 characters. The second line states the total number of buildings needing new marble numbers on that order. Then follows the different house number specifications on several lines. These lines are of two kinds: single number lines and multiple number lines. A single number line simply consists of the house number by itself, while a multiple number line starts with a “+”-sign, followed by three positive integer numbers: first number, last number and the interval between the house numbers. The distance between the first and last house number will always be a multiple of the house number interval. A house number will never have more than five digits. After the last house number specification line, the next order follows, if there is any.

样例输入:

1
Short Street
23 addresses
+ 101 125 2
275
+ 100 900 100

样例输出:

Short Street
23 addresses
Make 23 digit 0
Make 22 digit 1
Make 5 digit 2
Make 4 digit 3
Make 1 digit 4
Make 5 digit 5
Make 1 digit 6
Make 4 digit 7
Make 1 digit 8
Make 3 digit 9
In total 69 digits

又是一个水题。。。本来以为需要推到公式,试了一下直接逐个判断就水过了。
不过,这题的输入挺麻烦的(*^__^*)

#include<stdio.h>
#include<string.h>
int d[10];
int set(int num){
    while(num){
        d[num%10]++;
        num /= 10;
    }
    return 0;
}
int make(int first, int last, int inter){
    if(inter < 0){
        first ^= last;
        last ^= first;
        first ^= last;
        inter = 0 - inter;
    }
    while(first <= last){
        set(first);
        first += inter;
    }
    return 0;
}
int main(){
    int n, f, l, inter, sum, i, j;
    char name[51], addr[20], s[10], ch;
    scanf("%d", &n);    
    while(n--){
        memset(d, 0, sizeof(d));
        getchar();
        gets(name);        
        scanf("%d%s", &sum, addr);       
        j = sum;
        do{
            scanf("%s", s);
            if(s[0] == '+' || s[0] == '-'){
                scanf("%d%d%d", &f, &l, &inter);
                if(s[0] == '-') inter *= -1;
                sum -= (l-f)/inter + 1;
                make(f, l, inter);
            }
            else{
                i = 0;
                while(s[i] != '\0'){
                    d[s[i++]-'0']++;
                }
                sum--;
            }
        }while(sum);
        printf("%s\n", name);
        printf("%d %s\n", j, addr);
        j = 0;
        for(i=0; i<10; i++){
            j += d[i];
            printf("Make %d digit %d\n", d[i], i);
        }
        printf("In total %d digit", j);
        if(j > 1) printf("s");
        printf("\n");
    }
    return 0;
}

 


  1. 站长好。我是一个准备创业的互联网小白,我们打算做一个有关国*际*游*学的平台。手上也有了一些境外资源。现阶段的团队现在没有cto.原意出让一些管理股寻找一个靠谱的技术专家做合伙人, 不知道是不是能得到您的帮助。发个帖子或者其他方式。期待您的回应。可以加我微信tianxielemon聊聊。

  2. 很高兴你会喜欢这个网站。目前还没有一个开发团队,网站是我一个人在维护,都是用的开源系统,也没有太多需要开发的部分,主要是内容整理。非常感谢你的关注。