【算法】-2013填空

package blueBridge;
import java.util.*;


public class testOne {
    /*
     * 题目
     * 判断1999年以后哪一个世纪末恰好为星期天,选择最近的年份
     * */
    public static void main(String[] args) {
        Calendar calendar=Calendar.getInstance();
        for(int year=1999;year<10000;year+=100) {
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, 11);
            calendar.set(Calendar.DAY_OF_MONTH, 31);
            if(calendar.get(Calendar.DAY_OF_WEEK)==1) {
                System.out.println(year);
                break;
            }
        }
    }    

}
package blueBridge;
import java.math.BigInteger;
import java.util.*;


public class testOne {
	/*
	 * 题目
	 * 求2^11213-1最后一百位
	 * */
	public static void main(String[] args) {
		BigInteger x=BigInteger.valueOf(2).pow(11213).subtract(BigInteger.ONE);
		String s=x.toString();
		int length=s.length();
		System.out.println(length);
		String ans=s.substring(length-100);
		System.out.println(ans);
	}	

}

package blueBridge;
import java.math.BigInteger;
import java.util.*;


public class testOne {
	/*
	 * 题目
	 * 四位数的两个价格,不小心挂反了,一个亏了200多,一个赚了800多,共赚558.求亏钱正确价格
	 * */
	public static void main(String[] args) {
		ArrayList<Price> a1=new ArrayList<Price>();
		ArrayList<Price> a2=new ArrayList<Price>();
		for(int i=1000;i<10000;i++) {
			String s=i+"";
			if(s.contains("3")||s.contains("4")||s.contains("7"))
				continue;
			String re_s=reverse(s);
			int i1=Integer.parseInt(re_s);
			int plus=i1-i;
			if(plus<-200 && plus>-300)
				a1.add(new Price(i,plus));
			if(plus<900 && plus>800)
				a2.add(new Price(i,plus));
			for(Price p1:a1) {
				for(Price p2:a2) {
					if(p1.plus+p2.plus==558) {
						System.out.println(p1.p);
						break;
					}
				}
			}
		}
	}	
	private static String reverse(String s) {
		char[] ans=new char[s.length()];
		for(int i=s.length()-1,j=0;i>=0;i--,j++) {
			char c=s.charAt(i);
			if(c=='6')
				ans[j]='9';
			else if(c=='9')
				ans[j]='6';
			else
				ans[j]=c;
		}
		return new String(ans);
	}
	private static class Price{
		int p;
		int plus;
		public Price(int p,int plus) {
			this.p=p;
			this.plus=plus;
		}
	}
}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值