| |

VerySource

 Forgot password?
 Register
Search
View: 769|Reply: 3

I am a novice to help

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-21 12:00:02
| Show all posts |Read mode
6) Convert Arabic numbers greater than 0 to less than 1000 into Roman numerals. The correspondence between Arabic numerals and Roman numerals is as follows:
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-4-30 18:30:01
| Show all posts
as follows? ? ? ? ? ?
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-5 11:15:01
| Show all posts
Take a look at the conversion procedure with Chinese characters, basically the same problem
Reply

Use magic Report

0

Threads

78

Posts

29.00

Credits

Newbie

Rank: 1

Credits
29.00

 China

Post time: 2020-5-5 11:45:02
| Show all posts
//52367.23
// Wu Wan two thousand three hundred Lu Shiqi Yuan two corner three points

#include <stdio.h>
#include <string.h>

char RMB [10] [3] = {"Zero", "One", "Two", "Three", "Wan", "Wu", "Lu", "柒", "捌", "玖"} ;
char value [13] [3] = {"zero", "pickup", "bai", "qian", "ten thousand", "pickup", "hundred", "thousand", "billion", "pickup" "Bai", "Qian", "Wan"};
char faction [2] [3] = {"角", "分"};

void StyleChange (const char * str)
{
  int i, j, k = 1, t = 0, s = 0; // k is used to indicate the position of the current operation (tens, hundreds ...)
  int n;
  char ValueSave [26] [3]; // Store integer part
  char FactionValue [2] [3]; // Store fractional part
 
  n = strlen (str);
  for (i = 0; i <n; i ++)
  {
    if (str [i] == '.')
    break;
  }
 
  if (i> 13)
  {
    printf ("Sorry, please enter the number below 1 trillion\n");
    return;
  }
  if (n-i> 3)
  {
    printf ("Sorry, please make sure that the two decimal places are\n");
    return;
  }
    strcpy (ValueSave [t ++], "元");
    if ((n-i> 1&&i == 1) || str [i-1]! = '0')
    strcpy (ValueSave [t ++], RMB [str [i-1]-'0']);
 
  for (j = i-2; j> = 0; j--) // Operation of integer part
  {
     if (str [j] == '0')
     {
      if (str [j + 1]! = '0')
      {
       strcpy (ValueSave [t ++], RMB [str [j]-'0']);
       k ++;
      }
      else
      {
        if (i> 4&&k == 8)
        {
           strcpy (ValueSave [t ++], value [k]);
        }
        if (i <= 8&&k == 4)
        {
           strcpy (ValueSave [t ++], value [k]);
        }
        k ++;
      }
      continue;
     }
     strcpy (ValueSave [t ++], value [k ++]);
     strcpy (ValueSave [t ++], RMB [str [j]-'0']);
  }
 
  k = 0; // Operation of decimal part
  for (j = i + 1; j <n; j ++)
  {
     strcpy (FactionValue [s ++], RMB [str [j]-'0']);
     strcpy (FactionValue [s ++], faction [k ++]);
  }
 
  for (j = t-1; j> = 0; j--)
  printf ("% s", ValueSave [j]);
  for (j = 0; j <s; j ++)
  printf ("% s", FactionValue [j]);
  printf ("\n");
}

int main ()
{
   char s [17];
   int n;
   while (gets (s)! = NULL)
   {
   n = strlen (s);
   if (n> 16)
   {
    printf ("Sorry, please enter the number below 1 trillion\n");
    return -1;
   }
   StyleChange (s);
   }
   return 0;
}


==================================
==================================
#include <stdio.h>
main ()
{
    char * ch [11];
    ch [0] = "\0"; ch [1] = "one"; ch [2] = "two"; ch [3] = "three"; ch [4] = "four";
    ch [5] = "five"; ch [6] = "six"; ch [7] = "seven"; ch [8] = "eight"; ch [9] = "nine"; ch [10] = "zero";
    char * dw [6];
    dw [2] = "ten"; dw [3] = "hundred"; dw [0] = "thousand"; dw [5] = "ten"; dw [4] = "billion"; dw [1] = "\0";
    char number [11]; int last, n, m, i, j, have;
    while (1)
    {
        scanf ("% s", number);
        last = 1; have = 0;
        for (i = 0; i <11&&number [i]! = '\0'; i ++);
        for (j = 0; j <i; j ++)
        {
                n = number [j] -48;
                m = i-j;
                if (have == 0&&m> 4&&m <9&&n) have = 1;
                if (last == 0&&n) printf (ch [10]);
                printf (ch [n]); if (n) printf (dw [m% 4]);
                if (m% 4 == 1)
                {
                       if (m == 5&&have) printf (dw [5]);
                       if (m == 9) printf (dw [4]);
                }
                last = n;
                                                                                                                 
        }
        printf ("\n");
    }
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list