Lettered Numeration System


TCEA State Programming Contest
April 28, 2001

Problem 2.4 Lettered Numeration System

General Statement: The number equivalents in this numeration system are as follows:

A = 1
B = 10
C = 100
D = 1000
E = 10000
F = 100000
G = 1000000

Read the lettered version of the number and convert it to its numerical equivalent.

Input: The first line in the data set is an integer that represents the number of data collections that follow. There are an unknown number of letters in each data set. The letter X is used to indicate the end of the collection of letters.

Output: Place values to the right of the first digit must all be filled. Use a zero for any missing letters. Do not use leading zeros.
The output is to be formatted exactly like that for the sample output given below.

Assumptions: The letters in the data will be in order from highest to lowest and all letters of the same value are grouped together. The X used to indicate the end of a data collection is not part of the data for the problem.

Sample Input:
3
CCBBBBAX
EEECCCCX
DCCCAAAAAAX

Sample Output:
241
30400
1306

Solutions:


#include <stdio.h>

int function (char x)
{
    switch (x) {

        case 'A' :
        return 1;

        case 'B' :
        return 10;

        case 'C' :
        return 100;

        case 'D' :
        return 1000;

        case 'E' :
        return 10000;

        case 'F' :
        return 100000;

        case 'G' :
        return 1000000;

    }

    return 0;
}

int main ()
{
    int dataSet;
    scanf ("%d", &dataSet);

    while ( dataSet-- ) {

        char a;
        int result = 0;

        while ( scanf ("%c", &a) && a != 'X' ) {

            result += function (a);
        }

        printf ("%d\n", result);
    }
    return 0;
}


Advertisements

4 thoughts on “Lettered Numeration System

  1. A SIMPLE PROGRAM FOR THIS PROBLEM WITH and header files.

    #include
    #include
    int main(){
    char word[100];
    int i,j,k,l,n,x;
    char temp=’A’;
    int m=1;
    int sum=0;
    printf(“please enter the number of inputs: “);
    scanf(“%d”,&x);
    printf(“\n”);
    fgets(word,100,stdin);
    for(i=1;i<=x;i++){
    sum=0;
    printf("enter a word with letters from A to G and terminate it with X: ");
    fgets(word,100,stdin);
    for(k=0;k<100;k++){if(word[k]=='\n'){word[k]='\0';}}
    l=strlen(word)-2;
    for(j=0;j<=l;j++){
    for(n=0,temp='A',m=1;n<7;n++,temp++,m=m*10){
    if(word[j]==temp){
    sum=sum+m;}}

    }
    printf("the numerical equivalent of %s is: %d\n",word,sum);
    printf("\n");
    }
    return 0;

    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s