/**
* @Author Tiam
* @Date 2022/6/28 13:13
* @Description: 7. 整数反转 victory
*/publicclassDemo06{publicstaticvoidmain(String[] args){System.out.println(reverse(2432));}publicstaticintreverse(int x){long n = x %10;while((x /=10)!=0){
n = n *10+ x %10;}if(n >Integer.MAX_VALUE || n <Integer.MIN_VALUE)return0;return(int)n;}}
/**
* @Author Tiam
* @Date 2022/6/28 19:02
* @Description: 8. 字符串转换整数 (atoi) victory
*/publicclassDemo07{publicstaticvoidmain(String[] args){// System.out.println(4365 / 100.0);// System.out.println(Character.digit('0', 10));System.out.println(myAtoi("-91283472332"));//System.out.println(Double.parseDouble("-43.234"));}publicstaticintmyAtoi(String s){if("".equals(s.trim()))return0;char[] chars = s.trim().toCharArray();long n =0;//标记负数int i =0, flag =0;if(!Character.isDigit(chars[i])){if(chars[i]=='-'){
flag =1;}else{if(chars[i]!='+')return0;}
i++;}for(; i < chars.length; i++){//判断是否为数字if(Character.isDigit(chars[i])){
n = n *10+Character.digit(chars[i],10);if(flag ==0&& n >Integer.MAX_VALUE){returnInteger.MAX_VALUE;}if(flag ==1&&-n <Integer.MIN_VALUE){returnInteger.MIN_VALUE;}}else{break;}}
n = flag ==0? n :-n;return(int) n;}}
/**
* @Author Tiam
* @Date 2022/6/29 8:12
* @Description: 9. 回文数 victory
*/publicclassDemo08{publicstaticvoidmain(String[] args){System.out.println(isPalindrome(121));}publicstaticbooleanisPalindrome(int x){if(x <0)returnfalse;int n =0, m = x;while(x >0){
n = n *10+ x %10;
x /=10;}return m == n ?true:false;}}
/**
* @Author Tiam
* @Date 2022/6/29 14:38
* @Description: 实现 pow(x, n) ,即计算 x 的整数 n 次幂函数(即,xn )。
*/publicclassDemo14{publicstaticvoidmain(String[] args){System.out.println(myPow(2.00000,-2147483648));System.out.println(myPow_(5,-1));}/** x的n次方,适用于正整数求幂 */publicstaticintmyPow_(int x,int n){int r =1;while(n >1){if((n &1)==1) r *= x;
x *= x;
n >>=1;}return r * x;}publicstaticdoublemyPow(double x,int n){//特殊情况if(x ==1)return1;if(x ==0)return0;if(x ==-1)return n %2==0?1:-1;if(n ==Integer.MIN_VALUE)return0.0;int flag =0;if(n <0){
n =-n;
flag =1;}double res =1.0;for(int i =0; i < n; i++){
res *= x;}return flag ==0? res :1/ res;}}