import java.util.*;
public class hd1041 {
/**
* @param args
*/
public static String add(String s){
char c[]=s.toCharArray();
int carry=0;
String sr="";
for(int i=c.length-1;i>=0;i--){
int t=Integer.parseInt(c[i]+"")+Integer.parseInt(c[i]+"")+carry;
carry=t/10;
sr=t%10+sr;
}
if(carry!=0)
sr=carry+sr;
return sr;
}
public static String add1(String s){
String str=s.substring(0, s.length()-1);
char c=s.charAt(s.length()-1);
int t=Integer.parseInt(c+"")+1;
return str+t;
}
public static String minus1(String s){
String str=s.substring(0, s.length()-1);
char c=s.charAt(s.length()-1);
int t=Integer.parseInt(c+"")-1;
return str+t;
}
public static String fun(int n) {
if (n == 1)
return "0";
else{
if(n%2==0)
return add1(add(fun(n-1)));
else
return minus1(add(fun(n-1)));
}
}
public static void main(String[] args) {
// TODO 自动生成方法存根
Scanner s = new Scanner(System.in);
while (s.hasNext()) {
int n = s.nextInt();
String str=fun(n);
System.out.println(str);
}
}
}
//***********************************************************************************************
注:结果正确,运行超时
posted on 2008-06-13 14:41
poower 阅读(123)
评论(0) 编辑 收藏