HDOJ 1230 火星A+B
来源:互联网 发布:淘宝怎么登录阿里旺旺 编辑:程序博客网 时间:2024/05/16 09:18
HDACM1230
思路:直接把相应位置的值相加,然后在进位,最后把不必要的前缀0去掉,然后输出(输出注意格式)
import java.util.Scanner;public class Main{ public static void main(String[] args) {// boolean prime[] = new boolean[200];// for (int i = 2; i < prime.length; i++) {// if (!prime[i]) {// for (int j = i*2; j < prime.length; j += i) {// prime[j] = true;// }// }// }// int j = 0;// for (int i = 2; i < prime.length; i++) {// if (!prime[i]) {// j++;// System.out.print(i+",");// if (j==26) {// break;// }// }// } int mars[] = {2,3,5,7,11,13,17,19,23,29,31,37,41, 43,47,53,59,61,67,71,73,79,83,89,97,101}; Scanner sc = new Scanner(System.in); while (sc.hasNext()) { String s1 = sc.next(); String s2 = sc.next(); String[] a = s1.split(""+','); String[] b = s2.split(""+','); if ("0".equals(a[0])&&"0".equals(b[0])) { break; } int sum[] = new int[26]; int j = 0; for (int i = a.length-1; i>=0; i--) { sum[j++] += Integer.parseInt(a[i]); } j = 0; for (int i = b.length-1; i>=0; i--) { sum[j++] += Integer.parseInt(b[i]); } int c = a.length > b.length ? a.length : b.length; for (int i = 0; i < c+1; i++) { if(sum[i]>=mars[i]){ sum[i] -= mars[i]; sum[i+1]++; } } int i = c; while (sum[i]==0) { i--; } while (i>0) { System.out.print(sum[i]+","); i--; } System.out.println(sum[0]); } sc.close(); }}
阅读全文
0 0
- HDOJ 1230火星A+B
- HDOJ 1230 火星A+B
- hdoj 1230 火星A+B
- hdoj 1230 火星A+B 【模拟】
- hdoj.1230 火星A+B 20140804
- **火星A+B(HDOJ)
- 1230 火星 A+B
- hdu 1230 火星A+B
- hdu 1230 火星A+B
- hdu 1230 火星A+B
- HDU 1230 火星A+B
- HUD 1230 火星A+B
- hdu-1230-火星A+B
- HDU 1230 火星A+B
- HDU 1230 火星A+B
- hdu 1230 火星A+B
- hdu 1230 火星A+B
- hdu 1230 火星A+B
- Echart报错 Error setOption should not be called during main process
- 块设备驱动代码及框架
- 求两个数最大值
- 理解正则化项l1和l2的区别
- 从损失函数的角度详解常见机器学习算法
- HDOJ 1230 火星A+B
- C Primer Plus(第6版)第九章 初学小结
- Linux存储设备的管理
- Go Web基础--Beego框架
- callWithArguments
- 九大内置对象
- Spark学习之(二)Spark 集群环境搭建(standalone)
- hdoj 1016 Prime Ring Problem
- 正则表达式总结