Openjudge-noi-the most out of books

Source: Internet
Author: User

Describe

It is assumed that the library has new M (10≤m≤999) books, which are authored by N (2≤n≤26) authors independently or in cooperation with one another. Assuming that the M book number is an integer (1 to 999) and the author's name is the letter (' A ' to ' Z '), please find out the author and his list of books that are the most involved in the book based on the list of book authors.

Input
The number of books entered in the first act m, the remaining m lines, each line is a book of information, where the first integer is the book number, followed by a space is an uppercase English letter consisting of a string of characters, each letter represents an author. Input data guarantees that only one author has the most out of the book.
Output
Output has multiple lines:
The first act is the most written letter of the author;
The number of authors of the second act of the book;
The remaining author's book Number (output in input order).
Sample input
11307 F895 H410 GPKCV567 SPIM822 YSHDLPM834 BXPRD872 LJU791 BPJWIA580 AGMVY619 NAFL233 pdjwxk
Sample output
P6410567822834791233
Source:
Introduction to the calculation of Peking University 06 psychology and the final exam
Idea: This problem, pretty simple, you can use the structure, statistics of the author of each book The most is who, and then cycle to determine which books, output can.
The code is as follows:
1#include <stdio.h>2#include <string.h>3 struct Book4 {5     intnum;6     Charwriter[ -];7 };8 intMain ()9 {Ten     intm,i,j; One     intXiabiao;//the most out of the book author subscript A     intLarge//The book The author of the most out of the book -     CharLarge2;//book the most author name -     intflag[ -];//count the number of occurrences of each author's name the     structBook a[999];//structure, storage number, author name -scanf"%d",&m); -      for(i=0;i< -; i++)//Initialize -     { +flag[i]=0; -     } +      for(i=0; i<m;i++)//Enter Number, author A     { atscanf"%d%s",&a[i].num,&a[i].writer); -     }     -      for(i=0; i<m;i++)//count the number of occurrences of each writer's name -     { -          for(j=0; J<strlen (A[i].writer); J + +) -         { inflag[a[i].writer[j]- $]++; -         } to     } +large=flag[0];  -      for(i=0;i< -; i++)//find out the writer who has the most books the     { *         if(Flag[i]>large)//If you find one that's bigger than it is, update $         {Panax Notoginsengxiabiao=i; -Large=Flag[i]; the         }         +     }  Alarge2=xiabiao+ $; theprintf"%c\n%d\n", Large2,large);//output The most book writer's name, number of works +      for(i=0; i<m;i++) -     { $          for(j=0; J<strlen (A[i].writer); J + +) $         { -             if(a[i].writer[j]==large2) -             { theprintf"%d\n", a[i].num); -                  Break; Wuyi             }             the         } -     } Wu     return 0; -}

Openjudge-noi-the most out of books

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.