Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

坑爹的cin·····终于过了,贴上来纪念……^_^

Posted by X__X at 2012-02-21 14:14:24 on Problem 1002
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
using namespace std;

int map[] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
int main()
{
    int n , x, N;
    char temp[50];
    cin >> N;
    n = N;
    int *count = new int [N];
    int *a = new int [N];
    memset(a,0,sizeof a * N);
    memset(count,0,sizeof count * N);
    while(n--)
    {
//        cin >> temp;
        scanf("%s",temp);//尼玛啊,scanf一次过,他瞄的cin死活过不鸟,cin你个垃圾!!!!!!
        x = 0;
        int length = strlen(temp);
        for (int i = 0; i < length; i++)
        {
            if(temp[i] == '-')
                continue;
            if(temp[i] >= '0' && temp[i] <= '9')
                x += (int)temp[i] - 0x30;
            else
                x += map[temp[i] - 'A'];
            x *= 10;
        }
        x /= 10;
        a[n] = x;
    }
//    cout << endl;
//        for (int i = 0; i < N; i++)
//    cout << a[i] << ' ';
//    cout << endl;
    qsort(a , N ,sizeof(int),compare);
//        for (int i = 0; i < N; i++)
//    cout << a[i] << ' ';
//    cout << endl;
    for (int i = 1; i < N; i++)
    {
        if(a[i] == a[i-1])
        {
            count[i] = count[i-1] + 1;
            count[i-1] = 0;
        }
    }
    bool flag = false;
    for (int i = 0; i < N; i++)
    {
        if(count[i] != 0)
        {
            flag = true;
            break;
        }
    }
    if(flag == false)
    {
        cout << "No duplicates." << endl;
        return 0;
    }
    for (int i = 0; i < N; i++)
    {
        if(count[i] == 0)
            continue;
//        p = 1000000;
//        for (int j = 0; j < 7; j++)
//        {
//            cout << a[i] / p % 10;
//            p /= 10;
//            if(j == 2)
//                cout << '-';
//        }
        printf("%03d-%04d %d\n",a[i]/10000,a[i]%10000,count[i] + 1);//有printf,cout你就滚吧!!
    }
//    for (int i = 0; i < N; i++)
//    cout << a[i] << ' ';
//    cout << endl;
    return 0 ;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator