C++ STL vector A1039 Course List for Student

 

 

#include <bits / STDC ++ H.> 
#include <math.h> 
#include < String >
 the using  namespace STD;
 const  int N = 40005 ;
 // Vector <Vector <>> int 
const  int M = 26 is * 26 is * 26 is * 10 + 1 ; // the name of the hash to the digital boundary 
Vector < int > the selectCourse [M]; // for each selected student course number 
int the getID ( char name []) {
     int ID = 0 ;
     for(int i=0;i<3;++i){
        id = id * 26 + (name[i] - 'A');
    }
    id = id * 10 + (name[3] - '0');
    return id;
}
int main(){
    char name[5];
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i=0;i<k;++i){
        int course,x;
        scanf("%d%d",&course,&x);
        for(int j=0;j<x;++j){
            scanf("%s",name);
            int id = getID(name);
            selectCourse[id].push_back(course);
        }
    }
    for(int i =0;i<n;++i){
        scanf("%s",name);
        int id = getID(name);
        Sort (the selectCourse [ID] .begin (), the selectCourse [ID] .end ()); // in ascending order 
        the printf ( " % S% D " , name, the selectCourse [ID] .size ()); // name, number elective 
        for ( int J = 0 ; J <the selectCourse [ID] .size (); ++ J) { 
            the printf ( " % D " , the selectCourse [ID] [J]); 
        } 
        the printf ( " \ n- " ); 
    } 
    System ( " PAUSE " );
     return  0 ; 
}

Guess you like

Origin www.cnblogs.com/JasonPeng1/p/12198206.html