POJ 1002 487-3279

考试月结束,刷水题恢复一下手感,明天开始正式写。

题意中文可见

注意:

  1.输出3-4格式,0补齐

  2.不知道Q Z怎么处理 ,视为0了

  3.输入时str开大,20的时候WA了

  

傻叉错:

  循环完有还有一个没处理

#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cctype>
using namespace std;
const int N = 30;
int f[N];
int a[100004];
void init()
{
    int i, j = 0, tim;
    for(i =  2; i <= 6; i++) {
        for(tim = 0; tim < 3; tim++) {
            f[j] = i;
            j++;

        }
    }
    f[j++] = 7;
    f[j++] = 0;
    f[j++] = 7;
    f[j++] = 7;

    for(i = 8; i <= 9; i++) {
        for(tim = 0; tim < 3; tim++) {
            f[j] = i;
            j++;
        }
    }
}
char str[40];
int main()
{
    init();
    int n, i, j, id = 0, temp;
    scanf("%d", &n);
    getchar();
    for(i = 1; i <= n; i++) {
        gets(str);
      //  puts(str);
        temp = 0;
        for(j = 0; str[j] !=''; j++) {
            if(str[j] == '-')   continue;
            if(isdigit(str[j])) {
                temp = temp * 10 + str[j] - '0';
            } else {
                temp = temp * 10 + f[str[j]-'A'];
            }
        }
        a[++id] = temp;
        //  printf("%d
", temp);
    }
    sort(a + 1, a + id + 1);
    temp = 0;
    bool ok = false;
    for(i = 2; i <= id; i++) {
        if(a[i] == a[i-1]) {
            temp ++;
            ok = true;
        } else {
            if(temp) {
                printf("%03d-%04d %d
", a[i-1] / 10000, a[i-1] % 10000, temp+1);
            }
            temp = 0;
        }
    }
    if(temp) {
        printf("%03d-%04d %d
", a[i-1] / 10000, a[i-1] % 10000, temp+1);
    }
    if(!ok) {
        puts("No duplicates.");
    }
    return 0;
}

  

原文地址:https://www.cnblogs.com/bbbbbq/p/4627609.html