【每日一算】开始
2014-10-24 02:09
176 查看
【金色十月线上编程比赛规则】 一个小女孩正在用左手手指数数,从1数到n。她从拇指算作1开始数起,然后,食指为2,中指为3,无名指为4,小指为5。接下来调转方向,无名指算作6,中指为7,食指为8,大拇指为9,如此反复。问最后会停在那个手指上?用编号1、2、3、4、5依次表示大拇指、食指、中指、无名指、小指。 输入格式: 输入多组数据。每组数据占一行,只包含一个整数n(1<=n<=1000000000)。 输出格式: 每组数据占一行,只包含一个介于1和5之间的整数,表示最后停留的手指
public static void main(String[] args) { Scanner sc = new Scanner(System.in); List<Integer> hands = new ArrayList<Integer>(); System.out.println("输入格式: 输入多组数据。每组数据占一行,只包含一个整数n(1<=n<=1000000000),以0结束!"); hands.add((Integer)sc.nextInt()); while(hands.get(hands.size()-1) != 0){ hands.add((Integer)sc.nextInt()); } hands.remove(hands.size()-1); int num = 0; Integer result = null; for (Integer hand : hands) { while (num != hand) { for (int i = 1; i <= 5; i++) { num++; if (num == hand) { result = i; break; } } if (num == hand) { break; } for (int i = 4; i >= 2; i--) { num++; if (num == hand) { result = i; break; } } } System.out.println(result); num = 0; result = null; } }
相关文章推荐
- 从今天开始,整理每日所学
- 【每日一题】练习开始咯~~
- 【每日一题】练习开始咯~~
- 再从萌新开始-Leetcode每日题解-287. Find the Duplicate Number
- 从每日工作清单开始对工作进行目标管理
- 每日.net生活,告别helloword从connection开始
- 从今日开始,每日必发两篇
- 再从萌新开始-Leetcode每日题解-345. Reverse Vowels of a String
- 决定要每日学英语—从今天开始。
- 技术生涯从龙年开始决战1000天的日志(每日更新)
- 从今天开始,每日一博
- 再从萌新开始-Leetcode每日题解-447. Number of Boomerangs
- 电话订票每日开始时间(几点放票) - 北京本地宝
- 开始锻炼,每日骑行20KM
- 从今天开始回复每日blog
- 从现在开始,记录下每日的学习经历
- 每日订单号从0001开始
- 20080604-从今天开始,每日签到
- 再从萌新开始-Leetcode每日题解-445. Add Two Numbers II
- 今天开始启用每日创建了