OJ1004

 1004,求字符串出现最多次数

package shiyantest;
import java.util.*;

public class OJ1004 {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		while(n!=0)
		{
			String[]  colors = new String[n];
			for(int i =0;i<n;i++)
			{
				colors[i] = in.nextLine();
			}
			int max =0;
			int id =0;
			int nowmax=0;
			for(int i=0;i<n;i++) {
				for(int j=0;j<i;j++) {
					if(colors[i].equals(colors[j]))
						nowmax++;
				}
				if(nowmax>max) {
					max = nowmax;
					id =i;
				}
			}
			System.out.println(colors[id]);
			n = in.nextInt();
			in.nextLine();
		}
	}

}

OJ 1005

周期的思想,除以77 49

package shiyantest;

import java.util.Scanner;

public class OJ1005{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a, b;
		int n;
		while (in.hasNext()) {
			a = in.nextInt();
			b = in.nextInt();
			n = in.nextInt();
			// 1 <= A, B <= 1000, 1 <= n <= 100,000,000
			if (a < 1 & a > 1000 & b < 1 & b > 1000 & b < 1 & a > 100000000)
				System.exit(0);
			if (a == 0 & b == 0 & n == 0)
				System.exit(0);
			int f[] = new int[49];
			for (int i = 0; i < 49; i++) {
				if (i == 1 || i == 0) {
					f[i] = 1;
				} else {
					f[i] = (a * f[i - 1] + b * f[i - 2]) % 7;
				}
			}
			System.out.println(f[(n-1) % 49]);
		}
		in.close();
	}
 
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值