尼玛,我保证我这题是对的,系统就说我是错的,求大神帮忙看!

a917390823 2014-10-29 10:35:53



import java.util.Scanner;

public class CSDNDemo {
private static int index=0;
private static int m[]=new int[3];
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n1=sc.nextInt();
fun(n1);
int n2=sc.nextInt();
fun(n2);
int n3=sc.nextInt();
fun(n3);
for(int x=0;x<m.length;x++){
System.out.println(m[x]);
}
sc.close();
}
public static void fun(int n){
if(n%8>5){
m[index]=10-(n%8);
}else if(n%8==0){
m[index]=2;
}else{
m[index]=n%8;
}
index++;
}
}
...全文
426 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
lliiqiang 2014-10-30
  • 打赏
  • 举报
回复
其实用最简单的数学方法,被8整除余几?
humanity 2014-10-30
  • 打赏
  • 举报
回复
引用 10 楼 humanity 的回复:
[quote=引用 9 楼 humanity 的回复:] 总感觉这是一个数学题,需要估算偏移量,就好像字符串的模式匹配一样。
一个轮回是9,我们至少应该先对9取整除取余数再来计算9之内的偏移量得到值。我们节省时间。 [/quote] 错了,每次拇指间隔8.
humanity 2014-10-30
  • 打赏
  • 举报
回复
引用 9 楼 humanity 的回复:
总感觉这是一个数学题,需要估算偏移量,就好像字符串的模式匹配一样。
一个轮回是9,我们至少应该先对9取整除取余数再来计算9之内的偏移量得到值。我们节省时间。
humanity 2014-10-30
  • 打赏
  • 举报
回复
总感觉这是一个数学题,需要估算偏移量,就好像字符串的模式匹配一样。
「已注销」 2014-10-30
  • 打赏
  • 举报
回复
「已注销」 2014-10-30
  • 打赏
  • 举报
回复
我提交通过的代码贴上,不用太感谢我,请叫我雷锋。
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		while(input.hasNext()) {
			int number = input.nextInt();
			int status = 1;
			int flag = 1;
			for(int i = 1; i < number; i++) {
				status += flag;
				if(status == 5 || status == 1){
					flag = -flag;
				}
			}
			System.out.println(status);
		}

	}	
}
a917390823 2014-10-30
  • 打赏
  • 举报
回复
引用 13 楼 u011371360 的回复:
import java.util.Scanner;


public class Test4 {

/**
* 小女孩数数问题
* @param args
*/
public static void main(String[] args) {

int x;
int result=0;
Boolean flag1=false;
Boolean flag2=false;
int [] results = new int [3];
int count = 0;

while(count<3) {
Scanner sc = new Scanner(System.in);
while(true) {
x = sc.nextInt();
if(x>0)
break;
System.out.println("输入有误,请重新输入!");
}

for(int i=1; i<=x; i++) {
if(result <= 1)
flag1 = true;
else if(result == 5)
flag2 = true;

if(result < 5 && flag1) {
flag2 = false;
result ++;
continue;
}
else if(result > 1 && flag2) {
flag1 = false;
result --;
continue;
}
}

results[count] = result;
result = 0;
count ++;
}
for(int i=0; i<3; i++) {
System.out.println(results[i]);
}
}

}

模拟了数数过程,只是时间复杂度略大

改了一下,这样做就是对的了,没这么复杂!
a917390823 2014-10-30
  • 打赏
  • 举报
回复
引用 7 楼 zhang5476499 的回复:
我提交通过的代码贴上,不用太感谢我,请叫我雷锋。
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);

		while(input.hasNext()) {
			int number = input.nextInt();
			int status = 1;
			int flag = 1;
			for(int i = 1; i < number; i++) {
				status += flag;
				if(status == 5 || status == 1){
					flag = -flag;
				}
			}
			System.out.println(status);
		}

	}	
}
我知道为什么错了,必须是while循环输入!
Archie_w 2014-10-30
  • 打赏
  • 举报
回复
import java.util.Scanner;


public class Test4 {

	/**
	 * 小女孩数数问题
	 * @param args
	 */
	public static void main(String[] args) {
		
		int x;
		int result=0;
		Boolean flag1=false;
		Boolean flag2=false;
		int [] results = new int [3];
		int count = 0;
		
		while(count<3) {
			Scanner sc = new Scanner(System.in);
			while(true) {
				x = sc.nextInt();
				if(x>0)
					break;
				System.out.println("输入有误,请重新输入!");
			}
			
			for(int i=1; i<=x; i++) {	
				if(result <= 1)
					flag1 = true;
				else if(result == 5)
					flag2 = true;
				
				if(result < 5 && flag1) {
					flag2 = false;
					result ++;
					continue;
				}
				else if(result > 1 && flag2) {
					flag1 = false;
					result --;
					continue;
				}
			}
			
			results[count] = result;
			result = 0;
			count ++;
		}
		for(int i=0; i<3; i++) {
			System.out.println(results[i]);
		}
	}

}
模拟了数数过程,只是时间复杂度略大
a917390823 2014-10-29
  • 打赏
  • 举报
回复
引用 4 楼 u011910676 的回复:
楼主网上有的http://blog.csdn.net/codeforcer/article/details/40381199
这个用的是c,不一样
百曉生 2014-10-29
  • 打赏
  • 举报
回复
题目要求或许是:你输入一个数,回车,会有一个输出,再输入,回车,又有输出。 楼主试试这样,我记得以前也做过一些在线编程题,就是这样的
wwfyfh 2014-10-29
  • 打赏
  • 举报
回复
楼主网上有的http://blog.csdn.net/codeforcer/article/details/40381199
百曉生 2014-10-29
  • 打赏
  • 举报
回复
import java.util.Scanner;
public class CSDNDemo {
private static int index=0;
private static int m[]=new int[3];
public static void main(String[] args) {
System.out.println(1000000001%8);
Scanner sc=new Scanner(System.in);
int n1=sc.nextInt();
fun(n1);
int n2=sc.nextInt();
fun(n2);
int n3=sc.nextInt();
fun(n3);
for(int x=0;x<m.length;x++){
System.out.println(m[x]);
}
sc.close();
}
public static void fun(int n){
if(n<=5){
m[index]=n;
}else{
if(n%8>5){
m[index]=10-(n%8);
}else if(n%8==0){
m[index]=2;
}else{
m[index]=n%8;
}
}
index++;
}
}
刚才网不好,我看到的代码是这样,现在看的不一样了,我再看看啊
a917390823 2014-10-29
  • 打赏
  • 举报
回复
引用 1 楼 u012421456 的回复:
楼主第六行是什么意思?
第六行?
百曉生 2014-10-29
  • 打赏
  • 举报
回复
楼主第六行是什么意思?

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧