zoukankan      html  css  js  c++  java
  • uva10420

    题目大意就是找出国家名字出现了多少次然后排序 输出次数。

    练习了一下sscanf

     

     

    Problem B
    List of Conquests
    Input: standard input
    Output: 
    standard output
    Time Limit: 
    2 seconds

    In Act I, Leporello is telling Donna Elvira about his master's long list of conquests:

    ``This is the list of the beauties my master has loved, a list I've made out myself: take a look, read it with me. In Italy six hundred and forty, in Germany two hundred and thirty-one, a hundred in France, ninety-one in Turkey; but in Spain already a thousand and three! Among them are country girls, waiting-maids, city beauties; there are countesses, baronesses, marchionesses, princesses: women of every rank, of every size, of every age.'' (Madamina, il catalogo è questo)

    As Leporello records all the ``beauties'' Don Giovanni ``loved'' in chronological order, it is very troublesome for him to present his master's conquest to others because he needs to count the number of ``beauties'' by their nationality each time. You are to help Leporello to count.

    Input

    The input consists of at most 2000 lines, but the first. The first line contains a number n, indicating that there will be nmore lines. Each following line, with at most 75 characters, contains a country (the first word) and the name of a woman (the rest of the words in the line) Giovanni loved. You may assume that the name of all countries consist of only one word.

    Output

    The output consists of lines in alphabetical order. Each line starts with the name of a country, followed by the total number of women Giovanni loved in that country, separated by a space.

    Sample Input

    3
    Spain Donna Elvira
    England Jane Doe
    Spain Donna Anna

    Sample Output

    England 1

    Spain 2

     1 #include <cstdio>
     2 #include <iostream>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <stdio.h>
     6 using namespace std;
     7 const int maxn = 2000+10;
     8 const int  cmax = 100;
     9 
    10 char country[maxn][cmax];
    11 int n;
    12 
    13 int str_cmp(const void* _a,const void* _b)
    14 {
    15     char *a  = (char*)_a;
    16     char *b = (char*)_b;
    17     return strcmp(a,b);
    18 }
    19 int main()
    20 {
    21     cin>>n;
    22     char temp[cmax];
    23     getchar();
    24     int last=0;
    25     for(int i=0;i<n;i++)
    26     {
    27         gets(temp);
    28 
    29         sscanf(temp,"%s",country[i]);
    30 
    31     }
    32 
    33    qsort ( country,n,sizeof(country[0]),str_cmp);
    34 
    35 
    36     for(int i=0;i<n;i++)
    37     {
    38         int num=1;
    39         char temp[cmax];
    40         strcpy(temp,country[i]);
    41         while(strcmp(temp,country[i+1])==0)
    42         {
    43             i++;
    44             num++;
    45         }
    46         cout<<temp<<" "<<num<<endl;
    47 
    48     }
    49 
    50     return 0;
    51 }
  • 相关阅读:
    TransactionScop事务机制的使用
    MVC无刷新上传图片并显示
    WebClient和WebRequest获取html代码
    Web.config配置详解
    分类和扩展有什么区别?可以分别用来做什么?分类有哪些局限性?分类的结构体里面有哪些成员?
    有序二维数组的查找
    生成Excel.xlsx文件 iOS
    charles Https抓包
    https 通信流程和Charles 抓包原理
    fastlane自动化打包ipa并发布到firim或者蒲公英
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3375115.html
Copyright © 2011-2022 走看看