此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
楼主【gqha0903】截止到2008-06-28 16:16:12的历史汇总数据(不包括此帖):
发帖数:1 发帖分:5
结贴数:1 结贴分:5
未结数:0 未结分:0
结贴率:100.00% 结分率:100.00%
敬礼!
楼主【gqha0903】截止到2008-06-28 16:16:12的历史汇总数据(不包括此帖):
发帖数:1 发帖分:5
结贴数:1 结贴分:5
未结数:0 未结分:0
结贴率:100.00% 结分率:100.00%
敬礼!
解决方案 »
- 求一些poi 操作excel的实例
- 100分 菜鸟问题,初学JAVA 大家帮忙看下 说下这是什么意思怎么用的越仔细越好 谢谢了 在线等
- 如何在普通java类中保存错误,并把错误传递到指定jsp页面上
- 如何将java文件生成web service? 更高要求
- hibernate问题:
- 急救!!!!!!!!!多谢大家了!!!!!!!!!!!!!!!!!在线等
- 总有一天要被tomcat折磨死了,现在已经精神崩溃了!
- cmp问题——能插入,但不能查询!!!
- jdbc-odbc连sybase的问题!
- 用myeclipse时出现不包含jdbcodbc.class 错误
- EJB QL语句查询
- hibernate分页很奇怪的问题,结果集合为0,但实际有100条记录
int k=0;
int j=0;
k=num/10
if(k>10){
if(k>3){
j=getCount(num)+1;
}else{
j=getCount(num);
}
}
if(k==0){
if(num>3){
return j+1;
}else{
return j;
} }
}盲写的没有调试通过 大概就是这个思想.
if(k>3){
j=j+getCount(num)+1;
}else{
j=j+getCount(num);
} 呵呵不好意思阿这个块刚才写错了.
if(k>10){
if(k>3){ 这个判断不是废的么
j=getCount(num)+1;
}else{
j=getCount(num);
}
}
我也写一个比较弱的算法,感觉自己算法还是太差,凑了半天才凑出来,以后也要多炼炼:_)
public class Test {
public static int f(int n) {
if(n<3) {
return 0;
}
int count = 0;
String s = String.valueOf(n);
int index = 0;
while(true){
index = s.indexOf("3", index);
if(index==-1){
break;
}
index++;
count++;
}
return f(n-1) + count;
}
public static void main(String args[]) {
System.out.println(f(500));
}
}
public static int f(int n) {
//initialize the array, 1 indicates quit, 0 indicates stay
int[] persons = new int[n];
for(int i=0; i<n; i++) {
persons[i]=0;
}
// persons who have been out the chain
int first = 0;
for(int i=0; i<n-1; i++){
int count = 0;
while(true){
if(persons[first % n]==0){
count++;
}
if(count==3) {
persons[first % n] = 1;
break;
}
first++;
}
}
//find the person position
int index = -1;
for(int i=0; i<n; i++) {
if(persons[i]==0) {
index = i + 1;
break;
}
}
return index;
}
public static void main(String args[]) {
System.out.println(f(4));
}
}
框架:
f(n)= 1 n=3
g(n)+f(n-1)函数g就是不断除10 累计3的个数第2题
int a[m]
//innitial
bool flag
j=0;
sum=m;
while(true){
f=0;
while(true){
f++;
if(a[j%m]!=0){j++ ;f++;}
if (f==1)break;
}
a[j%m]=0;
sum--; while(true){
j++;
if(a[j%m]!=0){
if(sum==1) return j%
break;
}
}
}
框架:
f(n)= 1 n=3
g(n)+f(n-1)函数g就是不断除10 累计3的个数第2题
int a[m]
//innitial
bool flag
j=0;
sum=m;
while(true){
f=0;
while(true){
f++;
if(a[j%m]!=0){j++ ;f++;}
if (f==1)break;
}
a[j%m]=0;
sum--; while(true){
j++;
if(a[j%m]!=0){
if(sum==1) return j%
break;
}
}
}
第二题也看到过用ArrayList拼出来一个import java.util.ArrayList;
public class Test {
public int doSomething(int num,final int PER_NUMER) {
ArrayList<Integer> desArray = new ArrayList<Integer>();
ArrayList<Integer> srcArray = new ArrayList<Integer>();
for(int i=0;i<num;i++){
desArray.add(i * 33);
srcArray.add(i * 33);
} System.out.println("共有号码:" + desArray.size() + ",以 " + PER_NUMER + " 报数");
if(desArray.size() <= 1){
return -1;
}
for(int i:desArray){
System.out.print(i + " ");
}
System.out.println();
int count = 0;
while(desArray.size() > 1) {
for (int i = 0; i < desArray.size(); i++) {
count++;
if (count % PER_NUMER == 0) {
System.out.println("出列号码:" + desArray.get(i));
desArray.remove(i);
i--;
count = 0;
}
}
}
System.out.println("剩余号码:" + desArray.get(0)); int i;
for(i=0;i<srcArray.size();i++){
if(srcArray.get(i) == desArray.get(0)){
System.out.println("位于次序:" + (i + 1));
}
}
return i + 1;
}
public static void main(String[] args){
new Test().doSomething(3,3);
}
}
算法效率不高
大家一起研究
import java.io.*;
public class Count3 {
private int count=0;
public static void main(String[] args) {
int n=0;
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请输入一个整数N:输入0退出");
try {
n=Integer.parseInt(input.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Count3 count3=new Count3();
while(n>0){
System.out.println("1到"+n+"之间出现3的次数为:"+count3.count(n));
System.out.println("输入一个整数N:输入0退出");
try {
n=Integer.parseInt(input.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("已退出");
}
public int count(int n){
int temp,k;
count=0;
for(int i=2;i<=n;i++){
if(i%10==3){
count++;
}
k=i;
while((temp=k/10)!=0){
if(temp%10==3){
count++;
}
k=temp;
}
}
return count;
}
}