zoukankan      html  css  js  c++  java
  • Cell Phone Contacts

    Modern cellular phones have a small chip, called a SIM card, that allows the phone to interface with the carrier's network. SIM cards also have a small amount of memory onboard where the user can store data, such as names, phone numbers, and e-mail addresses. A common problem with SIM card memory is that it cannot group several numbers under the same name, as most cell phones can. This poses a problem when the user wishes to switch phones. The easiest way to transfer contacts is to copy them to the SIM card from the old phone, and then copy them back from the SIM card to the new phone. However, if the user has multiple phone numbers and/or e- mail addresses for a given name, the contact information will be broken up, with multiple entries of the same name, each associated with a different phone number or e-mail address.

    Obviously, the user of the new phone would like for his or her contact data to be organized, with each contact's name listed only once, and the various phone numbers and e-mail addresses for that contact organized under that single entry. You are to write a program to help with this.

    The Problem:

    Given the contact data from a SIM card, consisting of pairs of names and email addresses or names and phone numbers, generate organized input data for the new cell phone. The new cell phone has a strict data format that must be followed precisely (the format is described in The Output section below).

    The Input:

    There will be multiple contact lists (test cases) to process. The first line of each contact list contains a single integer, n(1 le n le 100)n(1n100), indicating the number of contact data entries on the SIM card. On each of the next nn lines will be a name, followed by either a phone number or an e-mail address. Names consist of exactly two strings of upper- and lower-case alphabetic characters (the first name followed by the last name). Each first (last) name is at least one character and at most 20 characters. There will be exactly one space between the first and last names in input, and one space between the last name and the phone number or e-mail address. A phone number will consist of exactly 10 digits (no hyphens). An e-mail address will consist of a string of letters and/or numbers separated by exactly one at ('@') sign, and at least one dot ('.'). No input line will exceed 80 characters. There will be no leading or trailing whitespace on any line.

    End of input is indicated by a value of 0 for nn. This case should not be processed.

    The Output:

    For each data set, print the heading "Contact list #d:" where dd is the set number in the input (starting with 1). Then, for each unique contact (by name) in the set, output a contact entry. Note that case is significant, so "John DOE" is a different contact from "John Doe". Contact entries must be output in the following format:

    <Contact Name>

    Phone:

    <Phone Number 1>

    <Phone Number 2>

    ...

    <Phone Number p>

    E-Mail:

    <E-Mail Address 1>

    <E-Mail Address 2>

    ...

    <E-Mail Address q>

    ###

    Phone numbers should be printed in the format "(123)456-7890". E-mail addresses should be printed exactly as input. Contact entries should be output in ascending ASCII order by last name, then first name. Within each contact, phone numbers should be output in numerical order, and e-mail addresses should be output in ascending ASCII order. There must be no leading or trailing spaces in the output. (Note that the built-in string comparison functions do compare strings in ASCII order.)

    Leave a blank line after the output for each data set. Follow the format illustrated in Sample Output.

    样例输入

    6
    John Doe 4071234567
    Bill Smith bsmith@somewhere.com
    Bill Smith 1231231234
    John Doe John.Doe@my.house.net
    John Doe John.Doe@work.com
    Bill Smith 1234567890
    2
    Bone Head 1231231234
    Air Head airhead@my.house.net
    0

    样例输出

    Contact list #1:
    John Doe
    Phone:
    (407)123-4567
    E-Mail:
    John.Doe@my.house.net
    John.Doe@work.com
    ###
    Bill Smith
    Phone:
    (123)123-1234
    (123)456-7890
    E-Mail:
    bsmith@somewhere.com
    ###
    
    Contact list #2:
    Air Head
    Phone:
    E-Mail:
    airhead@my.house.net
    ###
    Bone Head
    Phone:
    (123)123-1234
    E-Mail:
    ###
    不知道为什么,vs2015上自定义map排序总是编译都要出错,用g++的编译器就很正常
    #include <iostream>
    #include <vector>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <queue>
    #include <map>
    #include <sstream>
    #include <cstdio>
    #include <cstring>
    #include <numeric>
    #include <cmath>
    #include <iomanip>
    #include <deque>
    #include <bitset>
    //#include <unordered_set>
    #include <unordered_map>
    //#include <bits/stdc++.h>
    //#include <xfunctional>
    #define ll              long long
    #define PII             pair<int, int>
    #define rep(i,a,b)      for(int  i=a;i<=b;i++)
    #define dec(i,a,b)      for(int  i=a;i>=b;i--)
    #define pb              push_back
    #define mk              make_pair
    using namespace std;
    int dir[4][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } };
    const long long INF = 0x7f7f7f7f7f7f7f7f;
    const int inf = 0x3f3f3f3f;
    const double pi = 3.14159265358979;
    const int mod = 998244353;
    const int N = 2e5+5;
    //if(x<0 || x>=r || y<0 || y>=c)
    
    inline ll read()
    {
        ll x = 0; bool f = true; char c = getchar();
        while (c < '0' || c > '9') { if (c == '-') f = false; c = getchar(); }
        while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
        return f ? x : -x;
    }
    
    ll gcd(ll m, ll n)
    {
        return n == 0 ? m : gcd(n, m%n);
    }
    ll lcm(ll m, ll n)
    {
        return m*n / gcd(m, n);
    }
    bool ismail(string s)
    {
        for (int i = 0; i < s.size(); i++)
            if (s[i] == '@')
                return 1;
        return 0;
    }
    struct node
    {
        set<string> phone, mail;
    };
    struct cmp
    {
        bool operator() (const pair<string, string> &a , const pair<string, string> &b)
        {
            if (a.second != b.second)
                return a.second < b.second;
            else
                return a.first < b.first;
        }
    };
    int main()
    {
        int n;
        int num = 1;
        while (cin >> n, n)
        {
            map<pair<string, string>, node,cmp> mp;
            for (int i = 0; i < n; i++)
            {
                string ff, ss,t;
                cin >> ff >> ss >> t;
                if (ismail(t))
                    mp[{ff, ss}].mail.insert(t);
                else
                {
                    t.insert(6, 1, '-');
                    t.insert(3, 1, ')');
                    t.insert(0, 1, '(');
                    mp[{ff, ss}].phone.insert(t);
                }
                    
            }
            printf("Contact list #%d:
    ", num++);
            for (auto p : mp)
            {
                cout << p.first.first << " " << p.first.second << endl;
                cout << "Phone:" << endl;
                for (auto po : p.second.phone)
                {
                    cout << po << endl;
                }
                cout << "E-Mail:" << endl;
                for (auto po : p.second.mail)
                {
                    cout << po << endl;
                }
                cout << "###" << endl;
            }
            cout << endl;
        }
        return 0;
    }
  • 相关阅读:
    spring的控制器如何传递数据到视图
    spring的控制器如何获取参数
    thymeleaf的官方网站
    如何编写spring mvc 项目
    如何创建spring web 工程(maven工程)
    如何下载spring sts
    使用请求包装器RequestWrapper 对博客内容进行编码
    使用apache-commons-lang3架构对HTML内容进行编码和反编码
    (转)Nginx+Php-fpm运行原理详解
    (转)FastCgi与PHP-fpm之间是个什么样的关系
  • 原文地址:https://www.cnblogs.com/dealer/p/12905202.html
Copyright © 2011-2022 走看看