Basic

Time Limit: 1000MS Memory Limit: 65536K

Total Submissions: 905 Accepted: 228

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 2739 (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

Waterloo local 2003.01.25

奇葩题,看了好几遍,把百度,谷歌都用上只能说,不懂

题意就是:

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

只是奇怪为什么放在排序专题里????

#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define LL long long
#define eps 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define CRR fclose(stdin)
#define CWW fclose(stdout)
#define WW freopen("output.txt","w",stdout)
#define RR freopen("input.txt","r",stdin) using namespace std; const int MAX=100100; char s[110]; int Oper(int sum,int i)
{
if(sum<2||sum>16)
{
return 0;
}
if(s[i]=='#')
{
return 0;
}
double ans=0;//这里要用double,用long long 都过不了,可能有的字符串太长会损失精度
int j;
for(j=i;s[j];j++)
{
if(s[j]=='#')
{
break;
}
if(sum>10)
{
if(s[j]>='0'&&s[j]<='9')
{
ans=ans*sum+s[j]-'0';
}
else if(s[j]>='a'&&s[j]<=sum-11+'a')
{
ans=ans *sum+10+s[j]-'a';
}
else
{
return 0;
}
}
else if(sum<=10)
{
if(s[j]>='0'&&s[j]<=sum-1+'0')
{
ans=ans*sum+s[j]-'0';
}
else
{
return 0;
}
}
}
if((s[j]=='#'&&s[j+1]=='\0')||(s[j]=='#'&&s[j+1]=='#'&&Oper(ans,j+2)))
{
return 1;
}
else
{
return 0;
}
} int main()
{
int n,i;
scanf("%d",&n);
while(n--)
{
scanf("%s",s);
int ans=0;
for(i=0;;i++)
{
if(s[i]>='0'&&s[i]<='9')
{
ans=ans*10+s[i]-'0';
}
else
{
break;
}
}
if((s[i]=='#'&&Oper(ans,i+1))||(s[i]=='\0'&&ans==0))
{
printf("yes\n");
}
else
{
printf("no\n");
}
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

Basic 分类: POJ 2015-08-03 15:49 3人阅读 评论(0) 收藏的更多相关文章

  1. 安装hadoop1.2.1集群环境 分类: A1_HADOOP 2014-08-29 15:49 1444人阅读 评论(0) 收藏

    一.规划 (一)硬件资源 10.171.29.191 master 10.173.54.84  slave1 10.171.114.223 slave2 (二)基本资料 用户:  jediael 目录 ...

  2. shell入门之变量测试 分类: 学习笔记 linux ubuntu 2015-07-10 15:49 31人阅读 评论(0) 收藏

    格式:test 测试条件 字符串测试: 注意空格: test str1 == str2 测试字符串是否相等 test str1 != str2 测试字符串是否不相等 test str1 测试字符串是否 ...

  3. POJ 1068 AC 2014-01-07 15:24 146人阅读 评论(0) 收藏

    POJ的题目都是英文的,所以,,,还是直接贴代码吧 #include<stdio.h> int main(){ int x,y,z; int n,nm,max; scanf("% ...

  4. PIE(二分) 分类: 二分查找 2015-06-07 15:46 9人阅读 评论(0) 收藏

    Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submissio ...

  5. 网站通用登录模块代码 分类: ASP.NET 2014-12-06 10:49 615人阅读 评论(0) 收藏

    1.HTML部分:     <form id="form1" runat="server">     <script src=".. ...

  6. 周赛-DZY Loves Chessboard 分类: 比赛 搜索 2015-08-08 15:48 4人阅读 评论(0) 收藏

    DZY Loves Chessboard time limit per test 1 second memory limit per test 256 megabytes input standard ...

  7. cf 61E. Enemy is weak 树状数组求逆序数(WA) 分类: Brush Mode 2014-10-19 15:16 104人阅读 评论(0) 收藏

    #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...

  8. max_flow(Dinic) 分类: ACM TYPE 2014-09-02 15:42 94人阅读 评论(0) 收藏

    #include <cstdio> #include <iostream> #include <cstring> #include<queue> #in ...

  9. 8大排序算法图文讲解 分类: Brush Mode 2014-08-18 11:49 78人阅读 评论(0) 收藏

    排序算法可以分为内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 常见的内部排序算法有:插入排序.希尔排序. ...

随机推荐

  1. 实现 DIV 固定定位在网页主体部分最右侧

    position:fixed 相对于窗口的固定定位,这个窗口可理解为可视窗口,除了浏览器自己的东西,剩下的就是这个可视窗口.而大部分的网页都是窄屏设计,比如说网页主体部分固定宽 1200px,或者自适 ...

  2. Web 安全的短板

  3. hdu 4998

    http://acm.hdu.edu.cn/showproblem.php?pid=4998 这道题,在比赛的时候看了很久,才明白题目的大意.都怪自己不好好学习英语.后来经过队友翻译才懂是什么意思. ...

  4. Python快速建站系列-Part.One-组装开发环境

    |版权声明:本文为博主原创文章,未经博主允许不得转载. 源代码都在github上:SmallStudyStation 现在是个demo,但回来会租个服务器,等功能完善了放到服务器上挂着,域名jusot ...

  5. CSS3 Transform Matrix

    css3中的transform让我们操作变形变得很简单,诸如,translate–移动,scale–缩放,rotate–旋转,skew–斜切.这几个属性很方便,也很简单,但是其中matrix我们就不常 ...

  6. 夺命雷公狗—angularjs—6—单条数据的遍历

    我们在实际的工作中常常会处理到一些数据的遍历,这些数据都是后端传到前端的,有些公司会让前端帮忙处理一点遍历的工作,废话不多说,直接上代: <!doctype html> <html ...

  7. 怎么学习C++?

    一个学习十年c++的建议如下: 其实学习C++的读书顺序应该是这样的(对于有C基础的朋友): C++ Primer Effective C++ Exceptional C++ Inside the C ...

  8. zw版【转发·台湾nvp系列Delphi例程】HALCON OverpaintRegion1

    zw版[转发·台湾nvp系列Delphi例程]HALCON OverpaintRegion1 unit Unit1;interfaceuses Windows, Messages, SysUtils, ...

  9. 【sinatra】修改默认ip绑定

    加入 # 默认的bind是127.0.0.1 set :bind, '0.0.0.0' #0.0.0.0之后你能通过lan访问这个服务器

  10. ADB server didn't ACK的解决方法

    异常信息如下: C:\Users\Administrator>adb devices* daemon not running. starting it now on port 5037 *ADB ...