ACM题库

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
int num = Integer.parseInt(in.nextLine());
int i=0;
StringBuffer buffer = new StringBuffer();
while(i<num){
String line[] = in.nextLine().split("\\s");
int first = fromStringToInt(line[0]);
int second = fromStringToInt(line[1]);
buffer.append(fromIntToString(first+second));
buffer.append("\n");
i++;
}
System.out.print(buffer);



}

public static int fromStringToInt(String str) {

int sum = 0;
int i = str.indexOf("i");
if (i != -1) {
if(i>0){
char iPrefix = str.charAt(i - 1);
if (Character.isDigit(iPrefix)) {
sum = sum + (iPrefix - 48);
} else
sum += 1;
}
else sum+=1;
}


int x = str.indexOf("x");
if (x != -1) {
if(x>0){
char xPrefix = str.charAt(x - 1);
if (Character.isDigit(xPrefix)) {
sum = sum + (xPrefix - 48) * 10;
} else
sum += 10;
}
else sum+=10;
}

int c = str.indexOf("c");
if (c != -1) {

if(c>0){
char cPrefix = str.charAt(c - 1);
if (Character.isDigit(cPrefix)) {
sum = sum + (cPrefix - 48) * 100;
} else
sum += 100;
}
else sum+=100;

}
int m = str.indexOf("m");
if (m != -1) {
if (m == 0)
sum += 1000;
else {
char mPrefix = str.charAt(m - 1);

sum = sum + (mPrefix - 48) * 1000;

}
}
return sum;
}

public static StringBuffer fromIntToString(int a){
StringBuffer str=new StringBuffer();

int m = a/1000;
int c = a%1000/100;
int x = a%1000%100/10;
int i = a%10;

str.append(m+"m"+c+"c"+x+"x"+i+"i");
int zeroindex = str.indexOf("0");
while(zeroindex!=-1){
str.delete(zeroindex, zeroindex+2);
zeroindex = str.indexOf("0");
}
int oneindex = str.indexOf("1");
while(oneindex!=-1){
str.deleteCharAt(oneindex);
oneindex = str.indexOf("1");
}
return str;
}
}
2871题

import java.text.DecimalFormat;
import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);
StringBuffer buffer = new StringBuffer();
String line = "";
double current;
double previous;

line = in.nextLine();
previous = Double.parseDouble(line);

while(true){
line = in.nextLine();
if(line.equals("999")) break;
current = Double.parseDouble(line);

double sub = current-previous;
DecimalFormat df = new DecimalFormat("#.00");

buffer.append(df.format(sub)+"\n");
previous = current;

}
System.out.print(buffer);
System.out.println("End of Output");


}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值