java非法表达的开始_非法的表达开始

** 问题陈述:

您将获得参加ACM-ICPC世界总决赛的N人名单 . 他们每个人都精通某个主题,或者他们不是 . 找出2人团队可以了解的最大主题数 . 并且还了解有多少团队可以知道最大数量的主题 .

注意假设a,b和c是三个不同的人,则(a,b)和(b,c)被计为两个不同的团队 .

输入格式

第一行包含两个整数,N和M,由单个空格分隔,其中N表示人数,M表示主题数 . N行跟随 . 每行包含一个长度为M的二进制字符串 . 如果第i行的第j个字符为1,则第i个人知道第j个主题;否则,他不知道这个话题 .

约束2≤N≤5001≤M≤500

输出格式

在第一行,打印2人团队可以知道的最大主题数 . 在第二行,打印可以知道最大主题数的2人团队的数量 .

**问题:当我想将2个数字maxTopic和numTeam声明为:时,我有2个错误(“非法开始表达”和“';'预期”):

public static int maxTopic = 0; public static int numTeam = 0;

**代码:

public class Solution {

public static void main(String[] args) {

/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */

Scanner in = new Scanner(System.in);

int ppl = in.nextInt(); // Number of people

int topic = in.nextInt(); // Number of topics

int A[]; // Array A to store information about topics known by everyone

public static int maxTopic = 0; // Maximum number of topics known

public static int numTeam = 0; // Maximum number of teams that know maxTopic

/* Read the information about topics

and save it to the array A */

for (int i = 0; i < ppl; i++)

A[i] = in.nextInt();

/* Now call the method addCheck() to check each pair of people */

for (int i = 0; i < ppl; i++)

for (int j = i + 1; j < ppl; j++)

Solution.addCheck(A[i], A[j], topic);

System.out.println(maxTopic);

System.out.println(numTeam);

}

/**

* Method used to add up 2 given numbers, check their sum,

* and update the values of maxTopic and numTeam (if possible)

* @param a First number

* @param b Second number

* @param digit Number of digits for a and b

*/

public void addCheck(int a, int b, int digit) {

int sum = a + b; // Calculate the sum of a and b

int numTopic = 0; // Number of topics known for a and b

boolean update = false; // True if the current pair has been used to update numTeam

for (int i = 1; i <= digit; i++) {

if (Solution.getNthDigit(sum, i) != 0)

numTopic++;

if (numTopic > maxTopic)

maxTopic = numTopic;

if ((update == false) && (maxTopic == numTopic)) {

numTeam++;

update = true;

}

}

}

/**

* Get the nth digit of an integer

* @param number The number being considered

* @param n The digit (starting from 1, counted from right to left)

* @return int The value of the nth digit

* Example: getNthDigit(123, 10, 1) produces 3

*/

public int getNthDigit(int number, int n) {

return (int) ((number / Math.pow(10, n - 1)) % 10);

}

}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值