vov44k

Untitled

Apr 24th, 2022 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class test {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in = new Scanner(System.in);
  7.         String str = in.nextLine();
  8.         String[] strParts = str.split(" ");
  9.         StringBuffer sb = new StringBuffer("abcd");
  10.         for (int i = 0; i < strParts.length; i++) {
  11.             if (strParts[i].equals(""))
  12.                 continue;
  13.             boolean f = true;
  14.             for (int j = 0; j < strParts[i].length(); j++) {
  15.                 if (strParts[i].charAt(j) == 'M' || strParts[i].charAt(j) == 'D' || strParts[i].charAt(j) == 'C' || strParts[i].charAt(j) == 'L' || strParts[i].charAt(j) == 'X' || strParts[i].charAt(j) == 'V' || strParts[i].charAt(j) == 'I')
  16.                     sb = new StringBuffer(strParts[i]);
  17.                 else
  18.                     f = false;
  19.  
  20.             }
  21.             if (f) {
  22.                 int res = 0;
  23.                 if (sb.indexOf("CM") >= 0) {
  24.                     res = res + 900;
  25.                     sb.delete(sb.indexOf("CM"), sb.indexOf("CM") + 2);
  26.                 }
  27.                 if (sb.indexOf("CD") >= 0) {
  28.                     res = res + 400;
  29.                     sb.delete(sb.indexOf("CD"), sb.indexOf("CD") + 2);
  30.                 }
  31.                 if (sb.indexOf("XC") >= 0) {
  32.                     res = res + 90;
  33.                     sb.delete(sb.indexOf("XC"), sb.indexOf("XC") + 2);
  34.                 }
  35.                 if (sb.indexOf("XL") >= 0) {
  36.                     res = res + 40;
  37.                     sb.delete(sb.indexOf("XL"), sb.indexOf("XL") + 2);
  38.                 }
  39.                 if (sb.indexOf("IX") >= 0) {
  40.                     res = res + 9;
  41.                     sb.delete(sb.indexOf("IX"), sb.indexOf("IX") + 2);
  42.                 }
  43.                 if (sb.indexOf("IV") >= 0) {
  44.                     res = res + 4;
  45.                     sb.delete(sb.indexOf("IV"), sb.indexOf("IV") + 2);
  46.                 }
  47.                 for (int k = 0; k < sb.length(); k++) {
  48.                     switch (sb.charAt(k)) {
  49.                         case 'M':
  50.                             res += 1000;
  51.                             break;
  52.                         case 'D':
  53.                             res += 500;
  54.                             break;
  55.                         case 'C':
  56.                             res += 100;
  57.                             break;
  58.                         case 'L':
  59.                             res += 50;
  60.                             break;
  61.                         case 'X':
  62.                             res += 10;
  63.                             break;
  64.                         case 'V':
  65.                             res += 5;
  66.                             break;
  67.                         default:
  68.                             res += 1;
  69.                     }
  70.                 }
  71.                 strParts[i] = "" + res;
  72.             }
  73.  
  74.         }
  75.         for (int j = 0; j < strParts.length; j++) {
  76.             System.out.print(strParts[j] + " ");
  77.         }
  78.  
  79.  
  80.     }
  81. }
Add Comment
Please, Sign In to add comment