@(刷题生活)

1002

  1. A+B for Polynomials (25)

时间限制400 ms 内存限制65536 kB 代码长度限制16000 B

This time, you are supposed to find A+B where A and B are two polynomials. 2 Input

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, …, K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10,0 <= NK < … < N2 < N1 <=1000.

Output

For each test case you should output the sum of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate to 1 decimal place.

Sample Input 2 1 2.4 0 3.2 2 2 1.5 1 0.5 Sample Output 3 2 1.5 1 2.9 0 3.2

/*
这题用了hash映射,将指数为Nk的系数映射到数组A[Nk]中。
*/



#include<stdio.h>
#define maxn  1024            //一开始我用的const int maxn=9;但是编译错误了,c里面好像是不能这么用设置成9并不能通过,要改成1024???为什么呢
                             //因为虽然1<=k<=10但k代表的是非0多项式的个数,所以总共不止k个

int main(){

    double A[maxn]={0},co=0;           //给数组A赋值为全0
    int k=0,k2 = 0,i=0,e=0;
    //输入第一个多项式
    scanf("%d",&k);
    for(i = 0;i < k;i++){
        scanf("%d",&e);
        scanf("%lf",&A[e]);
    }

    //输入第二个多项式并进行相加运算
    scanf("%d",&k);
    for(i = 0;i < k;i++){
        scanf("%d",&e);
        scanf("%lf",&co);
        A[e] = A[e] + co;           //进行加法运算  
    }

    for(i = 0;i<maxn;i++){
        if(A[i]!=0) k2++;
    }
    printf("%d",k2);              //输出多项式中非0的项目个数

    for(i = maxn-1;i>=0;i--){
        if(A[i]!=0){
            printf(" %d %.1lf",i,A[i]);
        }
    }
    return 0;
}

1003

As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered(分散) cities connected by some roads. Amount of rescue teams in each city and the length of each road between any pair of cities are marked on the map. When there is an emergency call to you from some other city, your job is to lead your men to the place as quickly as possible, and at the mean time, call up as many hands on the way as possible.

Input

Each input file contains one test case. For each test case, the first line contains 4 positive integers: N (<= 500) - the number of cities (and the cities are numbered from 0 to N-1), M - the number of roads, C1 and C2 - the cities that you are currently in and that you must save, respectively. The next line contains N integers, where the i-th integer is the number of rescue teams in the i-th city. Then M lines follow, each describes a road with three integers c1, c2 and L, which are the pair of cities connected by a road and the length of that road, respectively. It is guaranteed that there exists at least one path from C1 to C2.

Output

For each test case, print in one line two numbers: the number of different shortest paths between C1 and C2, and the maximum amount of rescue teams you can possibly gather. All the numbers in a line must be separated by exactly one space, and there is no extra space allowed at the end of a line.

Sample Input 5 6 0 2 1 2 1 5 3 0 1 1 0 2 2 0 3 1 1 2 1 2 4 1 3 4 1 Sample Output 2 4

/*这题是求图上的两点之间最短路径有几条。用深度优先来求。
*/

#include<stdio.h>
#include<limits.h> //为了用INT_MAX,表示整数的最大数值

#define MAX 1024
//声明全局变量
int count,max,predist,n,visit[MAX],dist[MAX][MAX],countTeam[MAX];;

void dfs(int start,int end,int d,int team);
int main(){
    int m,start,end,i,c1,c2,j,dis;  
    predist = INT_MAX,count = 0;
    scanf("%d %d %d %d",&n,&m,&start,&end);
    for(i = 0;i<n;i++){
        scanf("%d",&countTeam[i]);
    }
    //初始化visit数组为0,dist数组为INT_MAX
    for(i = 0;i<n;i++){
        visit[i] = 0;
        for(j = 0;j<n;j++){
            dist[i][j] = INT_MAX;
        }
    }
    for(i = 0;i<m;i++){
        scanf("%d %d %d",&c1,&c2,&dis);
        if(dist[c1][c2]>dis){
            dist[c1][c2] = dist[c2][c1] = dis;  //这边注意,要将两个数组值都赋值
        }
    }
    dfs(start,end,0,countTeam[start]);

    printf("%d %d\n",count,max);
    return 0;

}

void dfs(int p,int end,int d,int team){
    //当已经达到最终的节点时,判断距离是否比已有的距离小,是的话就将最小距离的变量值改变,如果相等,就比较哪个队伍多,将队伍多的值付给现有的
    //队伍最大值。
    if(p==end){
        if(d<predist){
            count = 1;  //输出有几条最短路径
            predist = d;  //predist一开始被赋值为INT_MAX
            max = team;
        }else if(d == predist){
            count++;
            if(team>max) max = team;
        }
        return;
    }
    if(d > predist) return;
    int i;
    //递归调用dfs.
    for(i = 0;i<n;i++){
    //如果城市没有被访问过(即visit[i]==0)而且两个城市之间是可连同的
        if(visit[i]==0&&dist[p][i]!=INT_MAX){
            visit[i] = 1;
            dfs(i,end,d+dist[p][i],team+countTeam[i]);
            visit[i] = 0;
        }
    }

}

1004

Counting Leaves (30)

A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.

Input Each input file contains one test case. Each case starts with a line containing 0 < N < 100, the number of nodes in a tree, and M (< N), the number of non-leaf nodes. Then M lines follow, each in the format:

ID K ID[1] ID[2] … ID[K] where ID is a two-digit number representing a given non-leaf node, K is the number of its children, followed by a sequence of two-digit ID’s of its children. For the sake of simplicity, let us fix the root ID to be 01.

Output For each test case, you are supposed to count those family members who have no child for every seniority level starting from the root. The numbers must be printed in a line, separated by a space, and there must be no extra space at the end of each line.

The sample case represents a tree with only 2 nodes, where 01 is the root and 02 is its only child. Hence on the root 01 level, there is 0 leaf node; and on the next level, there is 1 leaf node. Then we should output “0 1” in a line.

Sample Input 2 1 01 1 02 Sample Output 0 1

/**
*题目的大概意思是求一棵树每层的没有孩子节点的节点数
**/
#include<stdio.h>
/**
*调用一个深度优先遍历的函数
**/
void dfs(int ids,int level,int no[],int chil[][110],int node){
    int i,flag=0;
    if(no[level] == -1) no[level] = 0;

    for(i = 1;i <= node;i++){
        if(chil[ids][i]==1){
            flag = 1;
            //递归调用,这里体现了是深度优先,遍历该ids的孩子i节点,在level+1层
            if(level+1 <= node) dfs(i,level+1,no,chil,node);
        }
    }
    if(flag == 0 ) no[level]++;
}

int main(){
    int nochild[110],chi[110][110];
    int n,m,i,j,id,child,son;
    // 初始化存贮每层没有孩子节点的节点总数,初始化二维数组代表每个i号节点所有的子节点编号,用j来记录子节点的编号,数组元素为1代表这个位置是有子节点
    for(i = 0;i <= 100;i++){
        nochild[i] = -1;
        for(j = 0;j <=100;j++){
            chi[i][j] = 0;
        }
    }

    scanf("%d%d",&n,&m);
    for(i = 1;i<=m;i++){
        scanf("%d%d",&id,&child);
        for(j = 1;j <= child;j++){
            scanf("%d",&son);
            chi[id][son] = 1;
        }
    }

    dfs(1,1,nochild,chi,n);

    for(i = 1;i <=n;i++){
        if(nochild[i] > -1&&i==1) printf("%d",nochild[i]);
        else if(nochild[i] > -1) printf(" %d",nochild[i]);
    }
    printf("\n");
    return 0;
}

1005

Spell It Right (20)

Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.

Input Specification:

Each input file contains one test case. Each case occupies one line which contains an N (<= 10100).

Output Specification:

For each test case, output in one line the digits of the sum in English words. There must be one space between two consecutive words, but no extra space at the end of a line.

Sample Input: 12345 Sample Output: one five

#include<stdio.h>

int main(){
    char num[101];  //开一个字符数组101长度,可以存储题目要求的长最多101的整数
    int sum = 0;
    char result[4];
    char ten[10][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
    int i,a,b,c,d;
    scanf("%s",num);
    for(i = 0;num[i]!='\0';i++){
        sum = sum + (num[i]-'0');
    }
    if(sum>=0&&sum<=9){
        printf("%s",ten[sum]);
    }
    else if(sum>=10&&sum<=99){
        a = sum/10;
        b = sum%10;
        printf("%s %s",ten[a],ten[b]);
    }
    else
    {
        a = sum/10;
        c = sum%10;
        d = a;
        a = a/10;
        b = d%10;
        printf("%s %s %s",ten[a],ten[b],ten[c]);
    }
    //for(i = 0;i<10;i++){
        //printf("%s\n",ten[i]);}
    //printf("%s\n",sum);
    //printf("%d\n",sum);

    return 0;
}

1006

Sign In and Sign Out (25)

At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given the records of signing in’s and out’s, you are supposed to find the ones who have unlocked and locked the door on that day.

Input Specification:

Each input file contains one test case. Each case contains the records for one day. The case starts with a positive integer M, which is the total number of records, followed by M lines, each in the format:

ID_number Sign_in_time Sign_out_time where times are given in the format HH:MM:SS, and ID number is a string with no more than 15 characters.

Output Specification:

For each test case, output in one line the ID numbers of the persons who have unlocked and locked the door on that day. The two ID numbers must be separated by one space.

Note: It is guaranteed that the records are consistent. That is, the sign in time must be earlier than the sign out time for each person, and there are no two persons sign in or out at the same moment.

Sample Input: 3 CS301111 15:30:28 17:00:10 SC3021234 08:00:00 11:25:25 CS301133 21:45:00 21:58:40 Sample Output: SC3021234 CS301133

/*
    基于时间的比较
*/


#include<stdio.h>

struct Record{
    char ID[15];     //工号
    int in;         //sign in 时间
    int out;        //sign out 时间
};

int main(){
    int m,i;
    struct Record p,p_in,p_out;  //这边要记得加struct
    int h1,m1,s1,h2,m2,s2;
    scanf("%d",&m);
    if(m == 0) return 0;
    scanf("%s%d%*c%d%*c%d %d%*c%d%*c%d",p.ID,&h1,&m1,&s1,&h2,&m2,&s2);
    p.in = h1*3600+m1*60+s1;     //将时间转换为秒来进行比较
    p.out = h2*3600+m2*60+s2;
    p_in = p_out=p;
    for(i = 1;i < m;i++){
        scanf("%s%d%*c%d%*c%d %d%*c%d%*c%d",p.ID,&h1,&m1,&s1,&h2,&m2,&s2);  //   %*c代表忽略输入的这个字符
        p.in = h1*3600+m1*60+s1;
        p.out = h2*3600+m2*60+s2;
        if(p.in<p_in.in) p_in = p;
        if(p.out>p_out.out) p_out = p;
    }

    printf("%s %s",p_in.ID,p_out.ID);

    return 0;
}

1007

Maximum Subsequence Sum (25)

Given a sequence of K integers { N1, N2, …, NK }. A continuous subsequence is defined to be { Ni, Ni+1, …, Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.

Now you are supposed to find the largest sum, together with the first and the last numbers of the maximum subsequence.

Input Specification:

Each input file contains one test case. Each case occupies two lines. The first line contains a positive integer K (<= 10000). The second line contains K numbers, separated by a space.

Output Specification:

For each test case, output in one line the largest sum, together with the first and the last numbers of the maximum subsequence. The numbers must be separated by one space, but there must be no extra space at the end of a line. In case that the maximum subsequence is not unique, output the one with the smallest indices i and j (as shown by the sample case). If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.

Sample Input: 10 -10 1 2 3 4 -5 -23 3 7 -21 Sample Output: 10 1 4

/*
一开始我理解错了题目的意思,题目的意思是输出sum以及子序列的第一个值和最后一个值,而不是我理解的第一个下标和最后一个下标


*/

#include<stdio.h>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
int main(){
    int n,i,j,num[10000],count,sum,temp,start,end,a;  //num数组一开始初始化为1024出错,要初始化为10000
    count = 0;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        scanf("%d",&num[i]);
        if(num[i]>0||num[i] == 0)  count++;
    }
    //如果所有的输入都是负数,就将和设为0,第一个数为第一个,最后一个数为最后一个,也可以映射出最后的和一定是大于等于0
    if(count == 0){
        printf("0 %d %d",num[0],num[n-1]);
        return 0;
    }
    sum = -1;                       //一开始我将sum的初始值赋值成num[0]出错。

    for(i = 0;i < n;i++){
        a = i;
        temp = 0;
        for(j = i;j < n;j++){
            temp = temp + num[j];
            if(temp > sum){
                sum = temp;
                start = num[a];
                end = num[j]; 
            }
        }
    }

    printf("%d %d %d",sum,start,end);
    return 0;
}

1008 Elevator

The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will stop, in specified order. It costs 6 seconds to move the elevator up one floor, and 4 seconds to move down one floor. The elevator will stay for 5 seconds at each stop.

For a given request list, you are to compute the total time spent to fulfill the requests on the list. The elevator is on the 0th floor at the beginning and does not have to return to the ground floor when the requests are fulfilled.

Input Specification:

Each input file contains one test case. Each case contains a positive integer N, followed by N positive numbers. All the numbers in the input are less than 100.

Output Specification:

For each test case, print the total time on a single line.

Sample Input: 3 2 3 1 Sample Output: 41

/**
*1008
**/
#include<stdio.h>
#include<math.h>
int main(){
    int n,i,j,a[20000],D_value,time;
    a[0] = 0;
    time = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++){
        scanf("%d",&a[i]);
        D_value = a[i] - a[i-1];
        if(D_value>0){
            time = time + D_value*6+5;
        }
        if(D_value<0){
            time = time + abs(D_value)*4+5;
        }
        if(D_value == 0){               //这边不要忘记了,一开始没有加,如果还是本层有人要上的话,就要将时间再多停留5S
            time = time + 5;            
        }
    }
    printf("%d",time);
}

1009 Product of Polynomials

This time, you are supposed to find A*B where A and B are two polynomials.

Input Specification:

Each input file contains one test case. Each case occupies 2 lines, and each line contains the information of a polynomial: K N1 aN1 N2 aN2 … NK aNK, where K is the number of nonzero terms in the polynomial, Ni and aNi (i=1, 2, …, K) are the exponents and coefficients, respectively. It is given that 1 <= K <= 10, 0 <= NK < … < N2 < N1 <=1000.

Output Specification:

For each test case you should output the product of A and B in one line, with the same format as the input. Notice that there must be NO extra space at the end of each line. Please be accurate up to 1 decimal place.

Sample Input 2 1 2.4 0 3.2 2 2 1.5 1 0.5 Sample Output 3 3 3.6 2 6.0 1 1.6

#include<stdio.h>
#include<stdlib.h>

typedef struct p1{           //这边的结构体必须要这样定义
    int expo;                    
    double coe;
}po;

int main(){
    int k1,k2,i,j,max,expo,count = 0;
     po *a,*b,*c;
    while(scanf("%d",&k1)!=EOF){
        a = (po*)malloc(k1*sizeof(po));      //开辟空间给数组a
        for(i = 0;i < k1;i++){
            scanf("%d %lf",&a[i].expo,&a[i].coe);
        }
        scanf("%d",&k2);
        b = (po*)malloc(k2*sizeof(po));      //开辟空间给数组b
        for(i = 0;i < k2;i++){
            scanf("%d %lf",&b[i].expo,&b[i].coe);
        }
        max = a[0].expo + b[0].expo;
        c = (po*)malloc((max+1)*sizeof(po));//为最后的成绩结果分配max+1的空间,因为指数是按递减进行排列的,所以直接先求出最大的指数是多少
        for(i = 0;i < max+1;i++){
            c[i].expo = i;
            c[i].coe = 0;                   
        }
        for(i = 0;i < k1;i++){
            for(j = 0;j < k2;j++){
                expo = a[i].expo + b[j].expo;
                c[expo].coe += a[i].coe*b[j].coe; //直接将指数作为下标,这样易于将指数相同的结合
            }
        }
        for(i = 0;i <= max;i++){
            if(c[i].coe!=0)       //这边算是考虑到了系数为0的情况
            {
                count++;
            }
        }
        printf("%d",count);
        for(i=max;i>=0;i--){
            if(c[i].coe!=0){
                printf(" %d %.1lf",i,c[i].coe);
            }
        }
    }
    return 0;
}

1010 Radix (25)

Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is “yes”, if 6 is a decimal number and 110 is a binary number.

Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given.

Input Specification:

Each input file contains one test case. Each case occupies a line which contains 4 positive integers: N1 N2 tag radix Here N1 and N2 each has no more than 10 digits. A digit is less than its radix and is chosen from the set {0-9, a-z} where 0-9 represent the decimal numbers 0-9, and a-z represent the decimal numbers 10-35. The last number “radix” is the radix of N1 if “tag” is 1, or of N2 if “tag” is 2.

Output Specification:

For each test case, print in one line the radix of the other number so that the equation N1 = N2 is true. If the equation is impossible, print “Impossible”. If the solution is not unique, output the smallest possible radix.

Sample Input 1: 6 110 1 10 Sample Output 1: 2 Sample Input 2: 1 ab 1 2 Sample Output 2: Impossible

#include<stdio.h>

//有一个过不了
#define  max  10240000

char  N[3][max];
long long int radix,num1,tag;
//将数字转化为长整型
long long int tolongint(char s[max],long long int dig){
    long long int ans=0;  
    long long int d=1; 
    int len=0;
    while(s[len]!='\0'){
            len++;
    }
    for(int i=len-1;i>=0;i--)  
    {  
        int num;  
        if(s[i]>='0' && s[i]<='9') num=s[i]-'0';  
        else num=s[i]-'a'+10;  

        ans=ans+num*d;  
        d*=dig;  
    }  
    return ans;  

}


//比较如果以dig为奇数,另一个数化为长整型后与num1比较的大小
int cmp(char s[max],long long int  dig)  
{  
    long long int ans=0;  
    long long int d=1;  
    int len=0;
    while(s[len]!='\0'){
            len++;
    }
    for(int i=len - 1;i>=0;i--)  
    {  
        int num;  
        if(s[i]>='0' && s[i]<='9') num=s[i]-'0';  
        else num=s[i]-'a'+10;  

        ans=ans+num*d;  
        if(ans>num1) return 1;  
        d*=dig;  
    }  
    if(ans==num1) return 0;  
    return -1;  
}  

//找出给出的数中最大的数字
int Maxnum(char s[max])  
{  
    int d=-1;  
    int len=0;
    while(s[len]!='\0'){
            len++;
    }
    for(int i=0;i<len;i++)  
    {  
        int num;  
        if(s[i]>='0' && s[i]<='9') num=s[i]-'0';  
        else num=s[i]-'a'+10;  

        if(num>d) d=num;  
    }  
    return d+1;  
} 


long long int Max(long long int a,long long int b)  
{  
    return a>b?a:b;  
} 

  //利用二分法来找基数
long long int BinarySearch(int cur)  
{  
    long long int L=Maxnum(N[cur]);  
    long long int R=Max(L,num1),M;  

    while(L<=R)  
    {  
        M=(L+R)/2;  
        int res=cmp(N[cur],M);  

        if(res==0) return M;  
        else if(res==1) R=M-1;  
        else L=M+1;  
    }  
    return -1;  
} 


int main(){
    //long long int i,num,d=1;

    while(scanf("%s %s %lld %lld",&N[1],&N[2],&tag,&radix)!=EOF){
    if(N[1]=="1"&&N[2]=="1")      //1上面是""而不是''
    {
        printf("2\n");
        continue;
    }
    else if(N[1]==N[2]){
        printf("%d\n",radix);
        continue;
    }

    num1=tolongint(N[tag],radix);  

        int cur;  
        if(tag==1) cur=2;  
        else cur=1;  

        long long int ans = BinarySearch(cur);  

        if(ans==-1) printf("Impossible\n");  
        else printf("%d\n",ans); 
    }  
    return 0;  

}

1011 World Cup Betting (20)

With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excited as the best players from the best teams doing battles for the World Cup trophy in South Africa. Similarly, football betting fans were putting their money where their mouths were, by laying all manner of World Cup bets.

Chinese Football Lottery provided a “Triple Winning” game. The rule of winning was simple: first select any three of the games. Then for each selected game, bet on one of the three possible results – namely W for win, T for tie, and L for lose. There was an odd assigned to each result. The winner’s odd would be the product of the three odds times 65%.

For example, 3 games’ odds are given as the following:

W T L 1.1 2.5 1.7 1.2 3.0 1.6 4.1 1.2 1.1 To obtain the maximum profit, one must buy W for the 3rd game, T for the 2nd game, and T for the 1st game. If each bet takes 2 yuans, then the maximum profit would be (4.13.02.565%-1)2 = 37.98 yuans (accurate up to 2 decimal places).

Input

Each input file contains one test case. Each case contains the betting information of 3 games. Each game occupies a line with three distinct odds corresponding to W, T and L.

Output

For each test case, print in one line the best bet of each game, and the maximum profit accurate up to 2 decimal places. The characters and the number must be separated by one space.

Sample Input 1.1 2.5 1.7 1.2 3.0 1.6 4.1 1.2 1.1 Sample Output T T W 37.98

#include<stdio.h>

struct game{
    double W;
    double T;
    double L;
};

int main(){
    struct game bet[3];
    int i =0,j=0,Mflag,mflag,sflag;
    double result=1,tmp,max;
    char tag[3] = {'W','T','L'};
    for( i = 0;i != 3;i++){
        max = 0;
        int pos = -1;
        for(j = 0;j != 3;j++){

            scanf("%lf",&tmp);
            //
            if((tmp-max)>1e-6){
                max = tmp;
                pos = j;
            }
        }
        result *= max; 
        printf("%c ",tag[pos]);
    }

    result = (result*0.65-1)*2;
    printf("%0.2f",result);
    return 0;

}

1012 The Best Rank (25)

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algebra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks – that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID C M E A 310101 98 85 88 90 310102 70 95 88 84 310103 82 87 94 88 310104 91 91 91 91 Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (<=2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output

For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output “N/A”.

Sample Input 5 6 310101 98 85 88 310102 70 95 88 310103 82 87 94 310104 91 91 91 310105 85 90 90 310101 310102 310103 310104 310105 999999 Sample Output 1 C 1 M 1 E 1 A 3 A N/A