题目
ACM HDU 1029 Ignatius and the Princess IV(JAVA)
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner ss = new Scanner(System.in);
long n, num, cnt, res = 0;
n = ss.nextLong();
while (true) {
if (!ss.hasNext()) break;
cnt = 0;
while (n!=0) {
n--;
num = ss.nextLong();
if (0 == cnt) {
res = num;
cnt++;
} else {
if (res == num)
cnt++;
else
cnt--;
}
}
System.out.println(res);
n = ss.nextLong();
}
}
}
为什么总是WA.
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner ss = new Scanner(System.in);
long n, num, cnt, res = 0;
n = ss.nextLong();
while (true) {
if (!ss.hasNext()) break;
cnt = 0;
while (n!=0) {
n--;
num = ss.nextLong();
if (0 == cnt) {
res = num;
cnt++;
} else {
if (res == num)
cnt++;
else
cnt--;
}
}
System.out.println(res);
n = ss.nextLong();
}
}
}
为什么总是WA.
提问时间:2021-01-29
答案
是读取的问题. 最后一组数据没有被处理
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner ss = new Scanner(System.in);
long n, num, cnt, res = 0;
while(ss.hasNextLong())
{
n = ss.nextLong();
cnt = 0;
while (n!=0) {
n--;
num = ss.nextLong();
if (0 == cnt) {
res = num;
cnt++;
} else {
if (res == num)
cnt++;
else
cnt--;
}
}
System.out.println(res);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner ss = new Scanner(System.in);
long n, num, cnt, res = 0;
while(ss.hasNextLong())
{
n = ss.nextLong();
cnt = 0;
while (n!=0) {
n--;
num = ss.nextLong();
if (0 == cnt) {
res = num;
cnt++;
} else {
if (res == num)
cnt++;
else
cnt--;
}
}
System.out.println(res);
}
}
}
举一反三
已知函数f(x)=x,g(x)=alnx,a∈R.若曲线y=f(x)与曲线y=g(x)相交,且在交点处有相同的切线,求a的值和该切线方程.
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
最新试题
- 1生活中常用碗炖食物(碗不与锅接触),当锅里的水沸腾后,碗中的汤( ) A.会沸腾的慢一点 B.同时沸腾 C.不会沸腾,温度为100℃ D.不会沸腾,温度低于100℃
- 2两道马哲多选题
- 3石墨是分子吗?书上又说中间有共价键 金属键 范德华力,所以不属于任何晶体?矛盾吗?
- 4将4个数a,b,c,d排成2行2列,两边各加一条竖直线记成,定义:,上述记号叫做2阶行列式.
- 5要制作一个由同底圆锥和圆柱组成的储油罐(如图),设计要求:圆锥和圆柱的总高度和圆柱底面半径相等,都为r米.市场上,圆柱侧面用料单价为每平方米a元,圆锥侧面用料单价分别是
- 6The boys ___(not have )an English class now.
- 7矩阵A满足A^3-2A^2-3A-E=0,证明A E可逆并求其逆矩阵
- 8可以把“月光洒在海面上”比喻成什么?急用啊,
- 9“每个sp3杂化轨道有1/4s和3/4p的成分”,轨道怎么1/4?
- 10生活中利用电磁铁来工作的物品有哪些?并说说它们有什么作用.
热门考点