package basic;
/**
* Created by zxc on 2018/3/23.
*/
public class ArithmeticTwo {
public static void main(String[] args) {
/* String roman = "XVIII";
int num = romanToNumber(roman, 0, roman.length() - 1);
System.out.println("Java3y--------------->" + num);*/
// beerAndDrink();
/* String s = "HELLO WORLD";
char[] ch = new char[s.length()];
for (int i = 0; i < s.length(); i++) {
ch[i] = (char) encode(s.charAt(i), 3);
}*/
int gcd = gcd(35, 5);
System.out.println("Java3y------------>" + gcd);
}
/**
*
*
* @param num1
* @param num2
*/
public static int gcd(int num1, int num2) {
//
int r = num1 % num2;
// 0
if (r == 0) {
return num2;
} else {
//
return gcd(num2, r);
}
}
/**
*
*/
public static int rotateRight(int ch) {
if (ch >= 'A' && ch = 'a' && ch = 'B' && ch = 'b' && ch 0) {
// shift
for (int i = 0; i < shift; i++) {
ch = rotateRight(ch);
}
return ch;
} else {
// shift
for (int i = 0; i < -shift; i++) {
ch = rotateLeft(ch);
}
return ch;
}
}
/**
*
*/
public static void beerAndDrink() {
//
for (int i = 0; i < 36; i++) {
//
for (int j = 0; j < 44; j++) {
//
if (2.3 * i + j * 1.9 == 82.3 && i < j) {
System.out.println("Java3y--------------->" + i);
}
}
}
}
/**
*
* -
*
* @param roman
* @return
*/
public static int digitsToValues(char roman) {
//
char digits[] = {'I', 'V', 'X', 'L', 'C', 'D', 'M'};
//
int values[] = {1, 5, 10, 50, 100, 500, 1000};
for (int i = 0; i < digits.length; i++) {
if (digits[i] == roman) {
return values[i];
}
}
return 0;
}
/**
*
*
* @param digits
* @return
*/
public static int findMaxIndex(String digits, int L, int R) {
//
int max = digitsToValues(digits.charAt(L));
int maxIndex = L;
for (int i = L; i < R; i++) {
//
int num = digitsToValues(digits.charAt(i));
if (max < num) {
max = num;
maxIndex = i;
}
}
return maxIndex;
}
/**
*
*
* @param romanNumber
* @param L
* @param R
*/
public static int romanToNumber(String romanNumber, int L, int R) {
// ()
if (L == R) {
return digitsToValues(romanNumber.charAt(L));
} else if (L > R) { // LR
return 0;
} else {
//
int maxIndex = findMaxIndex(romanNumber, L, R);
//
int max = digitsToValues(romanNumber.charAt(maxIndex));
//
int left = romanToNumber(romanNumber, L, maxIndex - 1);
//
int right = romanToNumber(romanNumber, maxIndex + 1, R);
return max - left + right;
}
}
/**
*
*/
public static void drawStar() {
// 5
int row = 5;
for (int i = 1; i
stack[++front] = arrays[i];
} else {
//
front--;
}
}
// 2/1
System.out.println("Java3y--->" + stack[0]);
}
public static void findMajorityElement2(int[] arrays) {
//
int candidate = -1;
// ()
int count = 0;
//
for (int i = 0; i < arrays.length; i++) {
//
if (count == 0) {
candidate = arrays[i];
count++;
} else if (candidate == arrays[i]) { // -->()
count++;
} else {
// -->()
count--;
}
}
// 2/1
System.out.println("Java3y--->" + candidate);
}
}