Exemplo n.º 1
0
int main()
{
    int input_count = 0;
    char input_str[MAX_INPUT_LEN] = {0};
    int *number_map;
    int *output_item_indexes;
    
    number_map = malloc(10000000*sizeof(int));
    memset(number_map,0,10000000);

    scanf("%d",&input_count);
    //printf("input count is %d\n",input_count);
    int i = 0;
    int content_digit = 0;
    while(input_count > 0){
        scanf("%s",input_str);
        removeDash(input_str);
        content_digit = atoi(input_str);
        //printf("--%d\n",content_digit);
        number_map[content_digit]++;
        input_count--;
    }
    //printf("finished.\n");
    int is_repeat = 0;
    for(i = 0; i < 10000000; i++){
        if(number_map[i] > 1){
            printf("%03d-%04d %d\n",i/10000,i%10000,number_map[i]);
            is_repeat = 1;
        }
    }
    if(is_repeat == 0)
        printf("No duplicates.\n");
    return 0;
}
Exemplo n.º 2
0
 string licenseKeyFormatting(string S, int K) {
     S = removeDash(S);
     int n = S.length();
     if (n <= K)
         return S;
     vector<char> chars;
     int count = 0;
     for (int i = n - 1; i >= 0; i--) {
         chars.push_back(S[i]);
         count++;
         if (count == K) {
             chars.push_back('-');
             count = 0;
         }
     }
     if (chars.back() == '-')
         chars.pop_back();
     return string(chars.rbegin(), chars.rend());
 }