ZQUOJ1395 / POJ2338解题报告

Basic

memory limit: 65536KB time limit: 500MS

Description

The programming language Ada has integer constants that look like this: 123, 8#123#, 16#abc#. These constants represent the integers 123, 83 (123 base 8) and 2748 (abc base 16). More precisely, an integer may be a decimal integer given as a sequence of one or more digits less than 10, or it may be an integer to some specific base, given as the base followed by a sequence of one or more digits less than the base enclosed by # symbols. Lower case letters from a through f are used as the digits representing 10 through 15. In Ada, the base, if specified, must be a sequence of decimal digits. For this problem, however, the base may be of any form described above so long as it represents an integer between 2 and 16 inclusive.

Input

The first line of input contains a positive integer n. n lines follow.Input lines contain no spaces and are between 1 and 80 characters in length.

Output

For each line of input, output a line "yes" if it is a valid integer constant according to the above rules; otherwise output a line containing "no".

Sample Input

5
2#101#
2#101##123#
17#abc#
16#123456789abcdef#
16#123456789abcdef#123456789abcdef#

Sample Output

yes
yes
no
yes
no

Source

ZQUCPC个人赛4

Author

Waterloo local

 

题意:

给一串字符串,判断是否合法。合法情况为:第一个数字在216间,表示进制的基底,然后是一个用两个#包含在内的数字,表示该进制下的数字,用af表示1015,新算出的值可以作为下一个数的基底(如果后面还有数的话)。

 

提交次数:

9次,其中8WA 1AC

 

问题的分析与解题思路:

这个题其实不难,挺水的,用递归可以解决。只是一些边缘问题要考虑,我就是因为这个贡献了8WA,主要还是粗心大意啊。

说一下注意的地方:

1.     注意精度问题,因为字符可以很长的,算出的数可能会超出整型范围,明显整型不能保存。

2.     给一串0是合法的,少##是不合法的,基底不能超出216的范围。

3.     某基底下的数的每一位都不能超出那个基底允许的范围。

4.     写递归函数时要将基底为10以上的分开来讨论。

 

AC方法和数据结构:

把字符串作为全局变量,构造一个递归函数,传入的值有两个,一个是基底,另一个是开始的‘#’后一维的位置。该递归函数返回1或者0,表示当前一步是否合法。主函数调用递归函数前先算出第一次的基底。

 

AC代码:

PS: 粗心你不得好死。。。。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值