今年寒假打算用Java把杭电2000-2099全部AC(现在持续更新),如下是题目链接,之后是我的题解,全部做完后我会把所有AC的题解打包上传的
题号 | 题名 | 题号 | 题名 |
---|---|---|---|
2000 | ASCII码排序 | 2001 | 计算两点间的距离 |
2002 | 计算球体积 | 2003 | 求绝对值 |
2004 | 成绩转换 | 2005 | 第几天? |
2006 | 求奇数的乘积 | 2007 | 平方和与立方和 |
2008 | 数值统计 | 2009 | 求数列的和 |
2010 | 水仙花数 | 2011 | 多项式求和 |
2012 | 素数判定 | 2013 | 蟠桃记 |
2014 | 青年歌手大奖赛_评委会打分 | 2015 | 偶数求和 |
2016 | 数据的交换输出 | 2017 | 字符串统计 |
2018 | 母牛的故事 | 2019 | 数列有序! |
2020 | 绝对值排序 | 2021 | 发工资咯:) |
2022 | 海选女主角 | 2023 | 求平均成绩 |
2024 | C语言合法标识符 | 2025 | 查找最大元素 |
2026 | 首字母变大写 | 2027 | 统计元音 |
2028 | Lowest Common Multiple Plus | 2029 | Palindromes _easy version |
2030 | 汉字统计 | 2031 | 进制转换 |
2032 | 杨辉三角 | 2033 | 人见人爱A+B |
2034 | 人见人爱A-B | 2035 | 人见人爱A^B |
2036 | 改革春风吹满地 | 2037 | 今年暑假不AC |
2038 | test | 2039 | 三角形 |
2040 | 亲和数 | 2041 | 超级楼梯 |
2042 | 不容易系列之二 | 2043 | 密码 |
2044 | 一只小蜜蜂... | 2045 | 不容易系列之(3)—— LELE的RPG难题 |
2046 | 骨牌铺方格 | 2047 | 阿牛的EOF牛肉串 |
2048 | 神、上帝以及老天爷 | 2049 | 不容易系列之(4)——考新郎 |
2050 | 折线分割平面 | 2051 | Bitset |
2052 | Picture | 2053 | Switch Game |
2054 | A == B n | 2055 | An easy problem |
2056 | Rectangles | 2057 | A + B Again |
2058 | The sum problem | 2059 | 龟兔赛跑 |
2060 | Snooker | 2061 | Treasure the new start, freshmen! |
2062 | Subset sequence | 2063 | 过山车 |
2064 | 汉诺塔III | 2065 | "红色病毒"问题 |
2066 | 一个人的旅行 | 2067 | 小兔的棋盘 |
2068 | RPG的错排 | 2069 | Coin Change |
2070 | Fibbonacci Number | 2071 | Max Num |
2072 | 单词数 | 2073 | 无限的路 |
2074 | 叠筐 | 2075 | A|B? |
2076 | 夹角有多大(题目已修改,注意读题) | 2077 | 汉诺塔IV |
2078 | 复习时间 | 2079 | 选课时间(题目已修改,注意读题) |
2080 | 夹角有多大II | 2081 | 手机短号 |
2082 | 找单词 | 2083 | 简易版之最短距离 |
2084 | 数塔 | 2085 | 核反应堆 |
2086 | A1 = n | 2087 | 剪花布条 |
2088 | Box of Bricks | 2089 | 不要62 |
2090 | 算菜价 | 2091 | 空心三角形 |
2092 | 整数解 | 2093 | 考试排名 |
2094 | 产生冠军 | 2095 | find your present (2) |
2096 | 小明A+B | 2097 | Sky数 |
2098 | 分拆素数和 | 2099 | 整除的尾数 |
目录
P2000.ASCII码排序
P2001.计算两点间的距离
P2002.计算球体积
P2003.求绝对值
P2004.成绩转换
P2005.第几天?
P2006.求奇数的乘积
P2007.平方和与立方和
P2008.数值统计
P2009求数列的和
P2010.水仙花数
P2011.多项式求和
P2012.素数判定
P2013.蟠桃记
P2014.青年歌手大奖赛_评委会打分
P2015.偶数求和
P2016.数据的交换输出
P2017.字符串统计
P2018.母牛的故事
P2019.数列有序!
P2020.绝对值排序
P2021.发工资咯:)
P2022.海选女主角
P2023.求平均成绩
P2024.C语言合法标识符
P2025.查找最大元素
P2026.首字母变大写
P2027.统计元音
P2028.Lowest Common Multiple Plus
P2029.Palindromes _easy version
P2030.汉字统计
P2031.进制转换
P2032.杨辉三角
P2033.人见人爱A+B
P2034.人见人爱A-B
P2035.人见人爱A^B
P2037.今年暑假不AC
P2038.test
P2039.三角形
P2040.亲和数
P2041.超级楼梯
P2042.不容易系列之二
P2043.密码
P2044.一只小蜜蜂...
P2045.不容易系列之(3)—— LELE的RPG难题
P2046.骨牌铺方格
P2047.阿牛的EOF牛肉串
P2048.神、上帝以及老天爷
P2049.不容易系列之(4)——考新郎
P2050.折线分割平面
P2051.Bitset
P2052.Picture
P2053.Switch Game
P2054.A == B ?
P2055.An easy problem
P2057.A + B Again
P2058.The sum problem
P2070.Fibbonacci Number
P2071.Max Num
P2072.单词数
P2073.无限的路
P2074.叠筐
P2075.A|B?
P2076.夹角有多大(题目已修改,注意读题)
P2080.夹角有多大II
P2081.手机短号
P2085.核反应堆
P2086.A1 = ?
P2087.剪花布条
P2089.不要62
P2090.算菜价
P2091.空心三角形
P2092.整数解
P2094.产生冠军
P2095.find your present (2)
P2096.小明A+B
P2097.Sky数
P2098.分拆素数和
P2099.整除的尾数
未完......(更新中)
版权声明
联系方式
package hdu经典100题;
import java.util.Scanner;
public class P2000 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
String str = in.next();
int a = str.charAt(0);
int b = str.charAt(1);
int c = str.charAt(2);
int temp;
if(b>a) {
temp = a;
a = b;
b = temp;
}
if(c>a) {
temp = a;
a = c;
c = temp;
}
if(c>b) {
temp = b;
b = c;
c = temp;
}
System.out.println((char)c+" "+(char)b+" "+(char)a);
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2001 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
double x1 = in.nextDouble();
double y1 = in.nextDouble();
double x2 = in.nextDouble();
double y2 = in.nextDouble();
DecimalFormat decimalFormat = new DecimalFormat(".00");
System.out.println(decimalFormat.format(Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2002 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
double r = in.nextDouble();
System.out.printf("%.3f\n",4.0/3.0*r*r*r*3.1415927);
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2003 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
double num = in.nextDouble();
DecimalFormat decimalFormat = new DecimalFormat(".00");
System.out.println(decimalFormat.format(Math.abs(num)));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2004 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int grade = in.nextInt();
if(grade<0 || grade>100) {
System.out.println("Score is error!");
}else {
switch (grade / 10) {
case 10:
System.out.println("A");
break;
case 9:
System.out.println("A");
break;
case 8:
System.out.println("B");
break;
case 7:
System.out.println("C");
break;
case 6:
System.out.println("D");
break;
default:
System.out.println("E");
break;
}
}
}
}
}
package hdu经典100题;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Scanner;
public class P2005 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
String date = in.next();
int year = Integer.valueOf(date.substring(0,4));
int month = Integer.valueOf(date.substring(5, date.lastIndexOf('/')));
int day = Integer.valueOf(date.substring(date.lastIndexOf('/')+1));
Calendar calendar = new GregorianCalendar(year, month-1, day);
System.out.println(calendar.get(Calendar.DAY_OF_YEAR));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2006 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
int cj = 1;
while(n!=0) {
int num = in.nextInt();
if(num%2!=0) {
cj = cj * num;
}
n--;
}
System.out.println(cj);
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2007 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int m = in.nextInt();
int n = in.nextInt();
int temp;
if(m>n) {
temp = m;
m = n;
n = temp;
}
int sumOu = 0;
int sumJi = 0;
for (int i = m; i <= n; i++) {
if(i%2==0) {
sumOu+=i*i;
}else {
sumJi+=i*i*i;
}
}
System.out.println(sumOu+" "+sumJi);
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2008 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
int amountFu = 0;
int amountZreo = 0;
int amountZheng = 0;
while(n!=0) {
double num = in.nextDouble();
if(num==0) {
amountZreo++;
}else if (num<0) {
amountFu++;
}else {
amountZheng++;
}
n--;
}
System.out.println(amountFu+" "+amountZreo+" "+amountZheng);
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2009 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
double n = in.nextInt();
int m = in.nextInt()-1;
double sum = n;
while(m!=0) {
sum+=Math.sqrt(n);
n = Math.sqrt(n);
m--;
}
DecimalFormat format = new DecimalFormat(".00");
System.out.println(format.format(sum));
}
}
}
package hdu经典100题;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class P2010 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int m = in.nextInt();
int n = in.nextInt();
List list = new ArrayList<>();
for (int i = m; i <=n; i++) {
String strNum = String.valueOf(i);
if(i==Integer.valueOf(String.valueOf(strNum.charAt(0)))*Integer.valueOf(String.valueOf(strNum.charAt(0)))*Integer.valueOf(String.valueOf(strNum.charAt(0)))
+Integer.valueOf(String.valueOf(strNum.charAt(1)))*Integer.valueOf(String.valueOf(strNum.charAt(1)))*Integer.valueOf(String.valueOf(strNum.charAt(1)))
+Integer.valueOf(String.valueOf(strNum.charAt(2)))*Integer.valueOf(String.valueOf(strNum.charAt(2)))*Integer.valueOf(String.valueOf(strNum.charAt(2)))
) {
list.add(i);
}
}
if(list.size()==0) {
System.out.println("no");
}else {
Collections.sort(list);
for (int i = 0; i < list.size()-1; i++) {
System.out.print(list.get(i)+" ");
}
System.out.println(list.get(list.size()-1));
}
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class P2011 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int m = in.nextInt();
int nums [] = new int [m];
for (int i = 0; i < nums.length; i++) {
nums[i] = in.nextInt();
}
List list = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
double sum =0;
for (int j = 1; j <=nums[i]; j++) {
if(j%2==0) {
sum+=(-1*1.0/j);
}else {
sum+=1.0/j;
}
}
list.add(sum);
}
DecimalFormat format = new DecimalFormat("0.00");
for (int i = 0; i < list.size(); i++) {
System.out.println(format.format(list.get(i)));
}
}
}
package hdu经典100题;
import java.util.Arrays;
import java.util.Scanner;
public class P2012 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
//模拟
int [] nums = new int[3000];
nums[2] = 0;
nums[3] = 0;
nums[5] = 0;
for (int i = 2; i < nums.length; i++) {
int j=2;
if(nums[i]==0) {
for (; j*i < nums.length; j++) {
nums[j*i] = 1;
}
}
}
while(in.hasNext()) {
int x = in.nextInt();
int y = in.nextInt();
if(x==0 && y==0) {
break;
}
int i;
for ( i = x; i <=y; i++) {
if(nums[(i*i+i+41)]!=0) {
break;
}
}
if(i==y+1) {
System.out.println("OK");
}else {
System.out.println("Sorry");
}
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2013 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt()-1;
int amount = 1;
while(n!=0) {
amount = 2*(amount+1);
n--;
}
System.out.println(amount);
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class P2014 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
List list = new ArrayList<>();
for (int i = 0; i < n; i++) {
list.add(in.nextDouble());
}
Collections.sort(list);
list.remove(0);
list.remove(list.size()-1);
double sum = 0;
for (int i = 0; i < list.size(); i++) {
sum+=list.get(i);
}
DecimalFormat format = new DecimalFormat("0.00");
System.out.println(format.format(sum/list.size()));
}
}
}
package hdu经典100题;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class P2015 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int[] nums = new int[100];
nums[0] = 2;
for (int i = 1; i < nums.length; i++) {
nums[i] = nums[i-1]+2;
}
while(in.hasNext()) {
int n = in.nextInt();
int m = in.nextInt();
List list = new ArrayList<>();
if(n%m==0) {
for (int i = 0; i < n; i+=m) {
int sum = 0;
for (int j = i; j < i+m;j++) {
sum+=nums[j];
}
list.add(sum/m);
}
}else {
int i = 0;
for (; i < n-(n%m); i+=m) {
int sum = 0;
for (int j = i; j < i+m;j++) {
sum+=nums[j];
}
list.add(sum/m);
}
int sum = 0;
m = n%m;
for (int j = i; j < n; j++) {
sum+=nums[j];
}
list.add(sum/m);
}
for (int i = 0; i < list.size()-1; i++) {
System.out.print(list.get(i)+" ");
}
System.out.println(list.get(list.size()-1));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2016 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
int[] nums = new int [n];
nums[0] = in.nextInt();
int minIndex = 0;
int temp;
for (int i = 1; i < nums.length; i++) {
nums[i] = in.nextInt();
if(nums[i]
package hdu经典100题;
import java.util.Scanner;
public class P2017 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
while(n!=0) {
String str = in.next().toLowerCase();
int amount =0;
for (int i = 0; i < str.length(); i++) {
if(str.charAt(i)>='0' && str.charAt(i)<='9') {
amount++;
}
}
System.out.println(amount);
n--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2018 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
long[] amount = new long [54];
amount[0] = 1;
amount[1] = 2;
amount[2] = 3;
amount[3] = 4;
for (int i = 4; i < amount.length; i++) {
amount[i] = amount[i-1]+amount[i-3];
}
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
System.out.println(amount[n-1]);
}
}
}
package hdu经典100题;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class P2019 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
int m = in.nextInt();
if(n==0 && m==0) {
break;
}
List list = new ArrayList<>();
int insert = n;
boolean isJ = false;
for (int i = 0; i < n; i++) {
list.add(in.nextInt());
if(list.get(i)>=m && !isJ) {
insert = i;
isJ = true;
}
}
list.add(insert, m);
for (int i = 0; i < list.size()-1; i++) {
System.out.print(list.get(i)+" ");
}
System.out.println(list.get(list.size()-1));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2020 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
int[] nums = new int [n];
for (int i = 0; i < nums.length; i++) {
nums[i] = in.nextInt();
}
int temp;
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j < nums.length-1-i; j++) {
if(Math.abs(nums[j+1])>Math.abs(nums[j])) {
temp = nums[j+1];
nums[j+1] = nums[j];
nums[j] = temp;
}
}
}
for (int i = 0; i < nums.length-1; i++) {
System.out.print(nums[i]+" ");
}
System.out.println(nums[nums.length-1]);
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2021 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int[] coins = new int[] {100,50,10,5,2,1};
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
int sum = 0;
while(n!=0) {
int num = in.nextInt();
while(num>0) {
for (int i = 0; i < coins.length; i++) {
if(num-coins[i]>=0) {
num = num - coins[i];
sum++;
break;
}
}
}
n--;
}
System.out.println(sum);
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2022 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int m = in.nextInt();
int n = in.nextInt();
int[][] grades = new int[m][n];
for (int i = 0; i < grades.length; i++) {
for (int j = 0; j < grades[i].length; j++) {
grades[i][j] = in.nextInt();
}
}
int maxX = 0;
int maxY = 0;
for (int i = 0; i < grades.length; i++) {
for (int j = 0; j < grades[i].length; j++) {
if(Math.abs(grades[i][j])>Math.abs(grades[maxX][maxY])) {
maxX = i;
maxY = j;
}
}
}
System.out.println((maxX+1)+" "+(maxY+1)+" "+grades[maxX][maxY]);
}
}
}
package hdu经典100题;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2023 {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
DecimalFormat df = new DecimalFormat("0.00");
df.setRoundingMode(RoundingMode.HALF_UP);
while(in.hasNext())
{
int n = in.nextInt();
int m = in.nextInt();
if (n == 0 && m == 0) break;
int students[][] = new int[n][m];
double classes [] = new double[m];
for (int i = 0 ; i < n ; i ++){
for (int k = 0 ; k < m ; k++) {
Integer score = in.nextInt();
students[i][k] = score;
classes[k] += score;
}
}
for (int i = 0 ; i < classes.length ; i ++) {
classes[i] = classes[i] / n; //课程平均成绩
}
int count = 0;
String studentAvg ="";
String classAvg = "";
for (int i = 0 ; i < n ; i ++) {
double sum = 0;
boolean excellentFlag = true;
for (int k = 0 ; k < m ; k ++) {
sum += students[i][k];
if (students[i][k] < classes[k]) {
excellentFlag = false;
}
}
if (excellentFlag) {
count ++;
}
studentAvg += df.format(sum / m) + " ";
}
for (int i = 0 ; i < m ; i ++) {
classAvg += df.format(classes[i]) + " ";
}
System.out.println(studentAvg.trim());
System.out.println(classAvg.trim());
System.out.println(count);
System.out.println();
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2024 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
while(n!=0) {
boolean isHf = true;
String str = in.nextLine().toLowerCase();
if((str.charAt(0)<'a' || str.charAt(0)>'z') && !(str.charAt(0)=='_')) {
isHf = false;
}else {
if( str.equals("main") ||
str.equals("float") ||
str.equals("auto") ||
str.equals("break") ||
str.equals("case") ||
str.equals("this") ||
str.equals("try") ||
str.equals("for") ||
str.equals("while") ||
str.equals("int") ||
str.equals("char") ||
str.equals("short") ||
str.equals("unsigned") ||
str.equals("printf") ||
str.equals("scanf")) {
isHf = false;
}else {
for (int i = 1; i < str.length(); i++) {
if(str.charAt(i)>='a' && str.charAt(i)<='z') {
continue;
}else if(str.charAt(i)>='0' && str.charAt(i)<='9'){
continue;
}else if(str.charAt(i)=='_') {
continue;
}else {
isHf = false;
break;
}
}
}
}
if(isHf) {
System.out.println("yes");
}else {
System.out.println("no");
}
n--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2025 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
StringBuffer str = new StringBuffer("");
str.append(in.next());
char maxWord = str.charAt(0);
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) > maxWord) {
maxWord = str.charAt(i);
}
}
int[] maxNum = new int[100];
int j = 0;
for (int i = 0; i < str.length(); i++) {
if (str.charAt(i) == maxWord) {
maxNum[j++] = i;
}
}
for (int i = 0; i < str.length(); i++) {
int k;
for (k = 0; k < j; k++) {
if (maxNum[k] == i) {
System.out.print(str.charAt(i) + "(max)");
break;
}
}
if (k == j) {
System.out.print(str.charAt(i));
}
}
System.out.println();
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2026 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
StringBuffer buffer = new StringBuffer(in.nextLine());
buffer.setCharAt(0, (char)(buffer.charAt(0)-32));
for (int i = 1; i < buffer.length()-1; i++) {
if(buffer.charAt(i)==' ') {
buffer.setCharAt(i+1, (char)(buffer.charAt(i+1)-32));
}
}
System.out.println(buffer.toString());
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2027 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
while (n != 0) {
int[] nums = new int[5];
String str = in.nextLine().toLowerCase();
for (int i = 0; i < str.length(); i++) {
switch (str.charAt(i)) {
case 'a':
nums[0]++;
break;
case 'e':
nums[1]++;
break;
case 'i':
nums[2]++;
break;
case 'o':
nums[3]++;
break;
case 'u':
nums[4]++;
break;
}
}
for (int i = 0; i < nums.length; i++) {
switch (i) {
case 0:
System.out.println("a:"+nums[i]);
break;
case 1:
System.out.println("e:"+nums[i]);
break;
case 2:
System.out.println("i:"+nums[i]);
break;
case 3:
System.out.println("o:"+nums[i]);
break;
case 4:
System.out.println("u:"+nums[i]);
break;
}
}
if((n-1)!=0)
System.out.println();
n--;
}
}
}
package hdu经典100题;
import java.util.Arrays;
import java.util.Scanner;
/**
* 使用最大数翻倍法
* @author Geek
* @version 1.0
* @date 2018年8月7日 下午12:41:52
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2028 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
int[] nums = new int[n];
for (int i = 0; i < nums.length; i++) {
nums[i] = in.nextInt();
}
Arrays.sort(nums);
int result = 1;
for (int i = 1;; i++) {
int j=0;
for (j = 0; j < nums.length-1; j++) {
if(i*nums[nums.length-1]%nums[j]!=0) {
break;
}
}
if(j==nums.length-1) {
result = i*nums[nums.length-1];
break;
}
}
System.out.println(result);
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2029 {
public static boolean isHw(String str) {
boolean isTrue = true;
for (int i = 0; i < str.length()/2; i++) {
if(str.charAt(i)!=str.charAt(str.length()-i-1)) {
isTrue = false;
break;
}
}
return isTrue;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
while(n!=0) {
String str = in.nextLine();
if(isHw(str)) {
System.out.println("yes");
}else {
System.out.println("no");
}
n--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 不是可显示字符的就是汉字
* @author Geek
* @version 1.0
* @date 2018年8月7日 下午7:57:07
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2030 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int n = in.nextInt();
in.nextLine();
while(n!=0) {
String str = in.nextLine();
int sum = 0;
for (int i = 0; i < str.length(); i++) {
if((int)str.charAt(i)<0 || (int)str.charAt(i)>127) {
sum++;
}
}
System.out.println(sum);
n--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2031 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int N = in.nextInt();
int R = in.nextInt();
System.out.println(Integer.toString(N, R).toString().toUpperCase());
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2032 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
int t = 0;
int[][] arr = new int[30][30];
arr[0][0] = 1;
arr[0][1] = 1;
arr[1][1] = 1;
if (t > 0) {
System.out.println();
}
for (int i = 0; i < n; i++) {// 层数
arr[i][0] = 1;
arr[i][n - 1] = 1;
for (int j = 0; j <= i; j++) {// 第几个
if (i == 0) {
System.out.print("1");
break;
} else {
if (i == 1) {
System.out.print("1" + " " + "1");
break;
} else {
if (j == 0) {
arr[i][j] = 1;
System.out.print(arr[i][j] + " ");
}
if (j >= 1 && j < i) {
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
System.out.print(arr[i][j] + " ");
}
if (j == i) {
arr[i][j] = 1;
System.out.print("1");
}
}
}
}
System.out.println();
}
System.out.println();
t++;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2033 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int N = in.nextInt();
while (N != 0) {
int[] times = new int[6];
for (int i = 0; i < times.length; i++) {
times[i] = in.nextInt();
}
int[] sumtimes = new int[3];
if (times[2] + times[5] > 59) {
sumtimes[2] = times[2] + times[5] - 60;
times[1]++;
} else {
sumtimes[2] = times[2] + times[5];
}
if (times[1] + times[4] > 59) {
sumtimes[1] = times[1] + times[4] - 60;
times[0]++;
} else {
sumtimes[1] = times[1] + times[4];
}
sumtimes[0] = times[0] + times[3];
for (int i = 0; i < sumtimes.length-1; i++) {
System.out.print(sumtimes[i] + " ");
}
System.out.println(sumtimes[sumtimes.length-1]);
N--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class P2034 {
/**
* 只属于集合A的元素不属于集合B的元素叫两个集合的差
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
int m = in.nextInt();
if(n==0 && m==0) {
break;
}
Set set = new TreeSet<>();
for (int i = 0; i < n; i++) {
set.add(in.nextInt());
}
int[] nums = new int[m];
for (int i = 0; i < nums.length; i++) {
nums[i] = in.nextInt();
}
for (int i = 0; i < nums.length; i++) {
if(set.contains(nums[i])) {
set.remove(nums[i]);
}
}
if(set.size()==0) {
System.out.println("NULL");
}else {
for (int i:set) {
System.out.print(i+" ");
}
System.out.println();
}
}
}
}
package hdu经典100题;
import java.math.BigInteger;
import java.util.Scanner;
public class P2035 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
BigInteger A = in.nextBigInteger();
int B = in.nextInt();
if(A.toString().equals("0") && B==0) {
break;
}
String str = A.pow(B).toString();
if(str.length()-3>=0) {
System.out.println(Integer.valueOf(str.substring(str.length()-3)));
}else {
System.out.println(str);
}
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 贪心算法,把结束时间按升序排列,然后下一个开始时间如果比前一个结束时间大的话计数器就加1
* @author Geek
* @version 1.0
* @date 2018年8月9日 下午10:52:00
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2037 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
int[][] times = new int[n][2];
for (int i = 0; i < times.length; i++) {
for (int j = 0; j < times[i].length; j++) {
times[i][j] = in.nextInt();
}
}
int temp;
for (int i = 0; i < times.length; i++) {
for (int j = 0; j < times.length-i-1; j++) {
if(times[j][1]>times[j+1][1]) {
temp = times[j][1];
times[j][1] = times[j+1][1];
times[j+1][1] = temp;
temp = times[j][0];
times[j][0] = times[j+1][0];
times[j+1][0] = temp;
}
}
}
int sum = 1;
int k = 0;
for (int i = 1; i < times.length; i++) {
if(times[i][0]>=times[k][1]) {
k = i;
sum++;
}
}
System.out.println(sum);
}
}
}
//我没找到题目=-=
package hdu经典100题;
import java.util.Scanner;
/**
* 题目的坑点就在于要定义一个实数
* @author Geek
* @version 1.0
* @date 2018年8月9日 下午10:10:35
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2039 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int M = in.nextInt();
while(M!=0) {
double A = in.nextDouble();
double B = in.nextDouble();
double C = in.nextDouble();
if(A+B>C && B+C>A && C+A>B) {
System.out.println("YES");
}else {
System.out.println("NO");
}
M--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2040 {
public static boolean isQhs(int A,int B) {
int sum = 1;
for (int i = 2; i < Math.sqrt(A); i++) {
if(A%i==0) {
sum = sum+i+(A/i);
}
}
if((int)Math.sqrt(A)*(int)Math.sqrt(A)==A) {
sum+=Math.sqrt(A);
}
if(sum==B) {
return true;
}
return false;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int M = in.nextInt();
while(M!=0) {
int A = in.nextInt();
int B = in.nextInt();
int temp;
if(A>B) {
temp = A;
A = B;
B = temp;
}
if(isQhs(A, B)) {
System.out.println("YES");
}else {
System.out.println("NO");
}
M--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 斐波那契数列
* @author Geek
* @version 1.0
* @date 2018年8月9日 下午10:55:46
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2041 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int [] jtNum = new int[40];
jtNum[0] = 0;
jtNum[1] = 1;
jtNum[2] = 2;
for (int i = 3; i < jtNum.length; i++) {
jtNum[i] = jtNum[i-1]+jtNum[i-2];
}
while(N!=0) {
int M = in.nextInt();
System.out.println(jtNum[M-1]);
N--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2042 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
while(N!=0) {
int a = in.nextInt();
int num = 3;
while(a!=0) {
num = 2*(num-1);
a--;
}
System.out.println(num);
N--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2043 {
private static void judge(String pwd) {
boolean isSafe = true;
if (pwd.length() < 8 || pwd.length() > 16) {
isSafe = false;
} else {
int score = 0;
if (pwd.matches(".*[A-Z]+.*")) // 大写字母
score++;
if (pwd.matches(".*[a-z]+.*")) // 小写字母
score++;
if (pwd.matches(".*[0-9]+.*")) // 数字
score++;
if (pwd.matches(".*[~!@#\\$%\\^]+.*")) // ~,!,@,#,$,%,^;
score++;
// 密码中的字符应该来自下面“字符类别”中四组中的至少三组
if (score < 3)
isSafe = false;
}
System.out.println(isSafe ? "YES" : "NO");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int M = in.nextInt();
in.nextLine();
while (M-- > 0)
judge(in.nextLine());
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2044 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
long[] nums = new long[49];
nums[0] = 1;
nums[1] = 2;
for (int i = 2; i < nums.length; i++) {
nums[i] = nums[i-1]+nums[i-2];
}
int N = in.nextInt();
while(N!=0) {
int a = in.nextInt();
int b = in.nextInt();
System.out.println(nums[b-a-1]);
N--;
}
}
}
递推分析
package hdu经典100题;
import java.util.Scanner;
public class P2045 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
long[] nums = new long[50];
nums[0] = 3;
nums[1] = 6;
nums[2] = 6;
for (int i = 3; i < nums.length; i++) {
nums[i] = nums[i-1]+nums[i-2]*2;
}
while(in.hasNext()) {
int n = in.nextInt();
System.out.println(nums[n-1]);
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 分析:
* 1.如果最后一块是竖块,所有的可能就是前面n-1种
* 2.如果最后一块是横块,那么所有可能就是前面的n-2种
* @author Geek
* @version 1.0
* @date 2018年8月11日 下午7:55:01
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2046 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long[] nums = new long[50];
nums[0] = 1;
nums[1] = 2;
nums[2] = 3;
for (int i = 3; i < nums.length; i++) {
nums[i] = nums[i-1]+nums[i-2];
}
while(in.hasNext()) {
int n = in.nextInt();
System.out.println(nums[n-1]);
}
}
}
package hdu经典100题;
import java.util.Scanner;
/** 分析:
* 1.如果最后一个字母是E或者F,那么就有2*(n-1)种可能
* 2.如果最后一个字母是O的话,那么倒数第二个字母可能是E或者F,那么就有就有2*(n-2)种可能
* @author Geek
* @version 1.0
* @date 2018年8月11日 下午8:21:45
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2047 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
long[] nums = new long[39];
nums[0]=3;
nums[1]=8;
for (int i = 2; i < nums.length; i++) {
nums[i] = 2*(nums[i-1]+nums[i-2]);
}
while(in.hasNext()) {
int n = in.nextInt();
System.out.println(nums[n-1]);
}
}
}
错排公式的分析
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
/**
* 使用错排公式f[n]=(n-1)*(f[n-1]+f[n-2])
* @author Geek
* @version 1.0
* @date 2018年8月11日 下午9:55:32
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2048 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int C = in.nextInt();
DecimalFormat decimalFormat = new DecimalFormat("0.00%");
double[] nums = new double[21];
nums[2] = 1;
nums[3] = 2;
for (int i = 4; i < nums.length; i++) {
nums[i] = (i-1)*(nums[i-1]+nums[i-2]);
}
while(C!=0) {
int n = in.nextInt();
double jc = 1;
for (int i = 2; i < n+1; i++) {
jc*=i;
}
System.out.println(decimalFormat.format(nums[n]/jc));
C--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 不要忘记组合中的错排了
* @author Geek
* @version 1.0
* @date 2018年8月30日 上午9:34:43
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2049 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long[] nums = new long[21];
nums[2] = 1;
nums[3] = 2;
for (int i = 4; i < nums.length; i++) {
nums[i] = (i - 1) * (nums[i - 1] + nums[i - 2]);
}
int C = in.nextInt();
while (C != 0) {
int M = in.nextInt();
int N = in.nextInt();
if (M == N) {
System.out.println(nums[N]);
} else {
long resultTop = 1;
long resultDown = 1;
for (int i = M; i > N; i--) {
resultTop *= i;
}
for (int i = 1; i <= (M - N); i++) {
resultDown *= i;
}
System.out.println(nums[N] * resultTop / resultDown);
}
C--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2050 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int C = in.nextInt();
long[] nums = new long[10000];
nums[0]=2;
nums[1]=7;
long k = 5;
for (int i = 2; i < nums.length; i++) {
nums[i] = nums[i-1]+(k+4);
k=k+4;
}
while(C!=0) {
int n = in.nextInt();
System.out.println(nums[n-1]);
C--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2051 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
System.out.println(Integer.toString(in.nextInt(), 2));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2052 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int weight = in.nextInt();
int height = in.nextInt();
for (int i = 0; i < height+2; i++) {
if(i==0 || i==height+1) {
System.out.print("+");
for (int j = 0; j < weight; j++) {
System.out.print("-");
}
System.out.println("+");
}else {
System.out.print("|");
for (int j = 0; j < weight; j++) {
System.out.print(" ");
}
System.out.println("|");
}
}
System.out.println();
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2053 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
int zt = 0;
for (int i = 1; i <=n; i++) {
if(n%i==0) {
if(zt==1) {
zt=0;
}else {
zt=1;
}
}
}
System.out.println(zt);
}
}
}
package hdu经典100题;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
/**
* 坑B,忘记了精度
* @author Geek
* @version 1.0
* @date 2018年8月12日 下午9:53:23
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2054 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
BigDecimal A = in.nextBigDecimal();
BigDecimal B = in.nextBigDecimal();
if(A.compareTo(B)==0) {
System.out.println("YES");
}else {
System.out.println("NO");
}
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2055 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T!=0) {
char c = in.next().charAt(0);
int num = in.nextInt();
if(c>='A' && c<='Z') {
System.out.println((c-64+num));
}else if(c>='a' && c<='z') {
System.out.println(-(c-96)+num);
}
T--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2057 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
String A = in.next();
String B = in.next();
System.out.println(Long.toString(Long.valueOf(A, 16)+Long.valueOf(B, 16), 16).toUpperCase());
}
}
}
解题传送门
package hdu经典100题;
import java.util.Scanner;
public class P2058 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
long N = in.nextLong();
long M = in.nextLong();
if(N==0 && M==0) {
break;
}
for (long i = (long) Math.sqrt(2*M); i>0; i--) {
N = ((2*M)/i+1-i)/2;
if((2*N+i-1)*i/2==M) {
System.out.println("["+N+","+(N+i-1)+"]");
}
}
System.out.println();
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2070 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long[] nums = new long[51];
nums[0] = 0;
nums[1] = 1;
for (int i = 2; i < nums.length; i++) {
nums[i] = nums[i-1]+nums[i-2];
}
while(in.hasNext()) {
int n = in.nextInt();
if(n==-1) {
break;
}
System.out.println(nums[n]);
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class P2071 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
List list = new ArrayList<>();
DecimalFormat decimalFormat = new DecimalFormat("0.00");
while(n!=0) {
int k = in.nextInt();
for (int i = 0; i < k; i++) {
list.add(in.nextDouble());
}
Collections.sort(list);
System.out.println(decimalFormat.format(list.get(list.size()-1)));
list.clear();
n--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class P2072 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Set set = new TreeSet<>();
while(in.hasNext()) {
String str = in.nextLine();
if(str.equals("#")) {
break;
}
String[] s = str.split(" ");
for (String string : s) {
if(!string.equals("")) {
set.add(string);
}
}
System.out.println(set.size());
set.clear();
}
}
}
分析传送门
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2073 {
private static final double sqrt2 = Math.sqrt(2);
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double[] nums = new double[201];
nums[0] = 0;
nums[1] = 1;
for (int i = 2; i < nums.length; i++) {
nums[i] = nums[i-1]+(i-1)*(sqrt2)+Math.sqrt(Math.pow(i, 2)+Math.pow(i-1, 2));
}
DecimalFormat format = new DecimalFormat("0.000");
int n = in.nextInt();
while(n!=0) {
double x1 = in.nextDouble();
double y1 = in.nextDouble();
double x2 = in.nextDouble();
double y2 = in.nextDouble();
double sum1 = nums[(int) (x1+y1)]+Math.sqrt(Math.pow(x1, 2)+Math.pow(x1, 2));
double sum2 = nums[(int) (x2+y2)]+Math.sqrt(Math.pow(x2, 2)+Math.pow(x2, 2));
System.out.println(format.format(Math.abs(sum2-sum1)));
n--;
}
}
}
分析传送门
package hdu经典100题;
import java.util.Scanner;
public class P2074 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int count = 0;
while (in.hasNext()) {
int n = in.nextInt();
if(count!=0) {
System.out.println();
}
char centerChar = in.next().charAt(0);
char outChar = in.next().charAt(0);
if(n==1) {
System.out.println(centerChar);
continue;
}
String[] dk = new String[(n + 1) / 2];
char temp;
if (((n + 1) / 2) % 2 == 0) {
temp = centerChar;
centerChar = outChar;
outChar = temp;
}
StringBuilder builder = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i == 0 || i == n - 1) {
builder.append(" ");
} else {
builder.append(centerChar);
}
}
dk[0] = builder.toString();
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < n; i++) {
if (i == 0 || i == n - 1) {
stringBuilder.append(centerChar);
} else {
stringBuilder.append(outChar);
}
}
for (int i = 1; i < dk.length; i++) {
if(i==1) {
dk[i] = stringBuilder.toString();
}else {
StringBuilder str = new StringBuilder();
char pj;
if(i%2==0) {
pj = centerChar;
}else {
pj = outChar;
}
for (int j = i; j < n-i; j++) {
str.append(pj);
}
stringBuilder.replace(i, n-i, str.toString());
dk[i] = stringBuilder.toString();
}
}
for (int i = 0; i < dk.length; i++) {
System.out.println(dk[i]);
}
for (int i = dk.length-2; i>=0; i--) {
System.out.println(dk[i]);
}
count++;
}
}
}
package hdu经典100题;
import java.math.BigInteger;
import java.util.Scanner;
public class P2075 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
BigInteger A;
BigInteger B;
while(T!=0) {
A = in.nextBigInteger();
B = in.nextBigInteger();
if(A.mod(B).toString().equals("0")) {
System.out.println("YES");
}else {
System.out.println("NO");
}
T--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* WA了好几次,终于发现了除的时候忘加了精度
* @author Geek
* @version 1.0
* @date 2018年8月15日 下午3:06:23
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2076 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T!=0) {
int h = in.nextInt();
int m = in.nextInt();
int s = in.nextInt();
if(h>=12) {
h = h-12;
}
double jj1 = 30*h+0.5*m+s/120.0;
double jj2 = m*6+0.1*s;
double k = Math.abs(jj1-jj2);
if(k>180) {
k=360-k;
}
System.out.println((int)k);
T--;
}
}
}
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2080 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
DecimalFormat format = new DecimalFormat("0.00");
while(T!=0) {
double x1 = in.nextDouble();
double y1 = in.nextDouble();
double x2 = in.nextDouble();
double y2 = in.nextDouble();
double jj1 = 0;
double jj2 = 0;
if(x1==0 && y1>0) {
jj1 = 90;
}else if (x1==0 && y1<0) {
jj1 = 270;
}else if (y1==0 && x1>0) {
jj1 = 0;
}else if (y1==0 && x1<0) {
jj1 = 180;
}else if (x1<0 && y1>0 || x1<0 && y1<0) {
jj1 = 180+Math.toDegrees(Math.atan(y1/x1));
}else if (x1>0 && y1<0) {
jj1 = 360+Math.toDegrees(Math.atan(y1/x1));
}else {
jj1 = Math.toDegrees(Math.atan(y1/x1));
}
if(x2==0 && y2>0) {
jj2 = 90;
}else if (x2==0 && y2<0) {
jj2 = 270;
}else if (y2==0 && x2>0) {
jj2 = 0;
}else if (y2==0 && x2<0) {
jj2 = 180;
}else if (x2<0 && y2>0 || x2<0 && y2<0) {
jj2 = 180+Math.toDegrees(Math.atan(y2/x2));
}else if (x1>0 && y1<0) {
jj2 = 360+Math.toDegrees(Math.atan(y2/x2));
}else {
jj2 = Math.toDegrees(Math.atan(y2/x2));
}
double result = Math.abs(jj2-jj1);
if(result>180) {
result = 360-result;
}
System.out.println(format.format(result));
T--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2081 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
while(N!=0) {
String str = in.next();
System.out.println(6+str.substring(str.length()-5));
N--;
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2085 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long[] numHigh = new long[34];
long[] numLow = new long[34];
numHigh[0] = 1;
for (int i = 1; i < numLow.length; i++) {
numHigh[i] = numHigh[i-1]*3+numLow[i-1]*2;
numLow[i] = numHigh[i-1]+numLow[i-1];
}
while(in.hasNext()) {
int n = in.nextInt();
if(n==-1) {
break;
}
System.out.println(numHigh[n]+", "+numLow[n]);
}
}
}
分析传送门
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.List;
import java.util.Scanner;
public class P2086 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
DecimalFormat format = new DecimalFormat("0.00");
while(in.hasNext()) {
int n = in.nextInt();
double a0 = in.nextDouble();
double anAdd1 = in.nextDouble();
double[] nums = new double[n];
for (int i = 0; i < nums.length; i++) {
nums[i] = in.nextDouble();
}
double result = n*a0+anAdd1;
int j = 2*n;
for (int i = 0; i < nums.length; i++) {
result = result - j*nums[i];
j=j-2;
}
System.out.println(format.format(result/(n+1)));
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2087 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String str = in.next();
if (str.equals("#")) {
break;
}
String sub = in.next();
int sum = 0;
for (int i = 0; i < str.length(); i++) {
if (i + sub.length() <= str.length()) {
if (str.substring(i, i + sub.length()).equals(sub)) {
sum++;
i = i + sub.length()-1;
}
}
}
System.out.println(sum);
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* MLE,搞了半天发现自己数组多打了一个1....然后内存就超了
* @author Geek
* @version 1.0
* @date 2018年8月19日 上午9:59:56
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2089 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int[] nums = new int[1000001];
for (int i = 0; i
package hdu经典100题;
import java.text.DecimalFormat;
import java.util.Scanner;
public class P2090 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
double sum = 0;
DecimalFormat format = new DecimalFormat("0.0");
while(in.hasNext()) {
String str = in.next();
double num = in.nextDouble();
double price = in.nextDouble();
sum+=num*price;
}
System.out.println(format.format(sum));
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 题面可能描述的有问题???输入的第一个测试与打印直接没有空格,其他都有
* @author Geek
* @version 1.0
* @date 2018年8月21日 下午9:10:43
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2091 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int sum = 0;
while(in.hasNext()) {
char c = in.next().charAt(0);
if(c=='@') {
break;
}
int n = in.nextInt();
sum++;
if(sum!=1) {
System.out.println();
}
for (int i = 0; i < n; i++) {
if(i==n-1) {
for (int j = 0; j < 2*n-1; j++) {
System.out.print(c);
}
System.out.println();
}else if (i==0) {
for (int j = 0; j < n-1-i; j++) {
System.out.print(" ");
}
System.out.println(c);
}
else {
for (int j = 0; j < n-1-i; j++) {
System.out.print(" ");
}
System.out.print(c);
for (int j = 0; j < 2*i-1; j++) {
System.out.print(" ");
}
System.out.println(c);
}
}
}
}
}
package hdu经典100题;
import java.util.Scanner;
public class P2092 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int sum = in.nextInt();
int cj = in.nextInt();
if(sum==0 && cj==0) {
break;
}
if(Math.pow(sum, 2)-4*cj>=0) {
double result = -sum+Math.sqrt(Math.pow(sum, 2)-4*cj);
if(result%2==0) {
System.out.println("Yes");
}else{
System.out.println("No");
}
}else {
System.out.println("No");
}
}
}
}
package hdu经典100题;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;
public class P2094 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
Set setA = new TreeSet<>();
Set set = new TreeSet<>();
int n = in.nextInt();
if(n==0) {
break;
}
for (int i = 0; i < n; i++) {
String winer = in.next();
String loser = in.next();
set.add(winer);
set.add(loser);
setA.add(loser);
}
if(setA.size()==set.size()-1) {
System.out.println("Yes");
}else {
System.out.println("No");
}
}
}
}
具体分析
package hdu经典100题;
import java.util.Scanner;
public class P2095 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
int n = in.nextInt();
if(n==0) {
break;
}
int result = 0;
for (int i = 0; i < n; i++) {
result^=in.nextInt();
}
System.out.println(result);
}
}
}
package hdu经典100题;
import java.util.Scanner;
/**
* 题意有问题
* @author Geek
* @version 1.0
* @date 2018年8月15日 下午6:14:48
* @TextDemo I hava a acDream
* @copyright
* @remark
*/
public class P2096 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T!=0) {
int A = in.nextInt()%100;
int B = in.nextInt()%100;
System.out.println((A+B)%100);
T--;
}
}
}
package hdu经典100题;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class P2097 {
static Map map = new HashMap<>();
public static boolean isSky(int num) {
int k = num;
int sumTen = 0;
//10进制
while(k!=0) {
sumTen+=k%10;
k=k/10;
}
//十六进制
String hash = Integer.toHexString(num).toUpperCase();
int sumHash = 0;
for (int i = 0; i < hash.length(); i++) {
sumHash+=map.get(hash.charAt(i));
}
//十二进制
String teString = Integer.toString(num, 12).toUpperCase();
int sumTe = 0;
for (int i = 0; i < teString.length(); i++) {
sumTe+=map.get(teString.charAt(i));
}
if(sumTen==sumHash && sumTen==sumTe) {
return true;
}
return false;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
map.put('0', 0);
map.put('1', 1);
map.put('2', 2);
map.put('3', 3);
map.put('4', 4);
map.put('5', 5);
map.put('6', 6);
map.put('7', 7);
map.put('8', 8);
map.put('9', 9);
map.put('A', 10);
map.put('B', 11);
map.put('C', 12);
map.put('D', 13);
map.put('E', 14);
map.put('F', 15);
while(in.hasNext()) {
int num = in.nextInt();
if(num==0) {
break;
}
if (isSky(num)) {
System.out.println(num+" is a Sky Number.");
}else {
System.out.println(num+" is not a Sky Number.");
}
}
}
}
package hdu经典100题;
import java.util.Arrays;
import java.util.Scanner;
public class P2098 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] nums = new int[10001];
nums[0] = 1;
nums[1] = 1;
nums[2] = 0;
nums[3] = 0;
nums[5] = 0;
for (int i = 2; i < nums.length; i++) {
if(nums[i]==0) {
for (int j = 2; i*j < nums.length; j++) {
nums[i*j] = 1;
}
}
}
while(in.hasNext()) {
int num = in.nextInt();
int sum = 0;
if(num==0) {
break;
}
for (int i = 2; i
package hdu经典100题;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class P2099 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
while(in.hasNext()) {
List list = new ArrayList<>();
long A = in.nextLong();
long B = in.nextLong();
if(A==0 && B==0) {
break;
}
for (int i = 0; i < 100; i++) {
String s;
if(i<10) {
s = "0"+i;
}else {
s = String.valueOf(i);
}
if(Long.valueOf((A+s))%B==0) {
list.add(s);
}
}
for (int i = 0; i < list.size()-1; i++) {
System.out.print(list.get(i)+" ");
}
System.out.println(list.get(list.size()-1));
}
}
}
本人的所有原创文章皆保留版权,请尊重原创作品。
转载必须包含本声明,保持本文完整,并以超链接形式注明原始作者
我的邮箱,欢迎来信([email protected])
我的CSDN博客(acDream_)