博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
2016 ThoughtWorks 校招编程作业
阅读量:4090 次
发布时间:2019-05-25

本文共 2423 字,大约阅读时间需要 8 分钟。

import java.text.SimpleDateFormat;import java.util.Calendar;public class Test {	public static int dayForWeek(String pTime) throws Exception {		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");		Calendar c = Calendar.getInstance();		c.setTime(format.parse(pTime));		int dayForWeek = 0;		if(c.get(Calendar.DAY_OF_WEEK) == 1){			dayForWeek = 7;		}else{			dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;		}		return dayForWeek;	}	public String generateSummary(String input){		String[] arr = input.split(" ");		int peopleNum = Integer.parseInt(arr[2]);		int yard = 0;		int T = peopleNum / 6;		int X = peopleNum % 6;		if(T == 0 && X < 4){			yard = 0;		}else if(T == 0 && X >= 4){			yard = 1;		}else if(T == 1){			yard = 2;		}else if((T == 2 || T == 3) && X >= 4){			yard = T + 1;		}else {			yard = T;		}				int weekday = -1;		try {			weekday = dayForWeek(arr[0]);		} catch (Exception e) {			e.printStackTrace();		}		//System.out.println(weekday);				int[][] charge = new int[8][24];		for(int i = 1; i <= 5; i++){			charge[i][9] = 30;			charge[i][10] = 30;			charge[i][11] = 30;			charge[i][12] = 50;			charge[i][13] = 50;			charge[i][14] = 50;			charge[i][15] = 50;			charge[i][16] = 50;			charge[i][17] = 50;			charge[i][18] = 80;			charge[i][19] = 80;			charge[i][20] = 60;			charge[i][21] = 60;		}		for(int i = 6; i <= 7; i++){			charge[i][9] = 40;			charge[i][10] = 40;			charge[i][11] = 40;			charge[i][12] = 50;			charge[i][13] = 50;			charge[i][14] = 50;			charge[i][15] = 50;			charge[i][16] = 50;			charge[i][17] = 50;			charge[i][18] = 60;			charge[i][19] = 60;			charge[i][20] = 60;			charge[i][21] = 60;		}		int[] timezone = new int[2];		String[] tempsplit = arr[1].split("~");		timezone[0] = Integer.parseInt(tempsplit[0].split(":")[0]);		timezone[1] = Integer.parseInt(tempsplit[1].split(":")[0]);		//System.out.println(timezone[0]+"--"+timezone[1]);		int income = peopleNum * 30;		int outcome = 0;		for(int i = timezone[0]; i < timezone[1]; i++) {			outcome += charge[weekday][i];		}		outcome *= yard;		if(yard == 0){			income = 0;		}		char lastchar = ((income - outcome)>0) ? '+' : '-';		int lastval = Math.abs(income - outcome);		String output = arr[0] + " " + arr[1] + " " + "+" + income				+ " " + "-" + outcome + " " + lastchar + lastval;		System.out.println(output);		return output;	}		public static void main(String[] args) {		Test t = new Test();		t.generateSummary("2016-06-02 20:00~22:00 7");	}}

你可能感兴趣的文章
Spring处理表单提交
查看>>
Spring MVC异常处理
查看>>
Leetcode 1180. Count Substrings with Only One Distinct Letter [Python]
查看>>
go语言web开发:3登录login
查看>>
php性能分析工具xhprof的安装与使用
查看>>
win10安装go语言, 并进行环境配置, 及liteide的简单实用
查看>>
laravel: 集成xhprof
查看>>
laravel: 集成laravel-admin管理后台
查看>>
laravel: 集成laravel/ui, 提供登录注册等功能
查看>>
PHP 7 的五大新特性
查看>>
php使用 memcache 来存储 session
查看>>
php实现socket(转)
查看>>
PHP底层的运行机制与原理
查看>>
php 几个比较实用的函数
查看>>
PHP5各个版本的新功能和新特性总结
查看>>
深入了解php底层机制
查看>>
PHP中的stdClass 【转】
查看>>
XHProf-php轻量级的性能分析工具
查看>>
PHP7新特性 What will be in PHP 7/PHPNG
查看>>
比较strtr, str_replace和preg_replace三个函数的效率
查看>>