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. Java String类详解

    Java String类详解 Java字符串类(java.lang.String)是Java中使用最多的类,也是最为特殊的一个类,很多时候,我们对它既熟悉又陌生. 类结构: public final ...

  2. maven中下载jar包源码和javadoc

    1:Maven命令下载源码和javadocs 当在IDE中使用Maven时如果想要看引用的jar包中类的源码和javadoc需要通过maven命令下载这些源码,然后再进行引入,通过mvn命令能够容易的 ...

  3. PostgreSQL Insight Monitor pgstat

    PostgreSQL Insight Monitor  pgstat pgstat 是一个连接到数据库并获取数据库的活动状态的命令行工具. PostgreSQL有许多状态: archiver for ...

  4. SQL top查询

    select *from emp;

  5. have you declared this activity in your AndroidManifest.xml

    对于那些刚开始接触安卓的开发者来说,遇到这个问题再正常不过了,出现这种问题的原因大概可分为: 1.android的四大组件都必须在AndroidMainifest.xml里面声明,所以首先看看有没有在 ...

  6. C++之路进阶——bzoj1823(满汉全席)

    F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser  hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...

  7. 活动组件(三):Intent

    大多数的安卓应用都不止一个Activity,而是有多个Activity.但是点击应用图标的时候,只会进入应用的主活动. 因此,前面我已经建立了一个主活动了,名字是myActivity,现在我再建立一个 ...

  8. bzoj2333 [SCOI2011]棘手的操作

    用set维护每个联通块里的最值,multiset维护所有块里的最值,并查集维护连通性,然后随便搞搞就行了,合并时候采用启发式合并.复杂度O(nlognlogn),大概勉强过的程度,反正跑的很慢就是了. ...

  9. ios pyudaren

    ed2k://|file|%E9%A1%B9%E7%9B%AE%E6%8D%95%E9%B1%BC%E8%BE%BE%E4%BA%BA01.rmvb|67044010|9e013987298d7900 ...

  10. (转)SQL Server 2005 中的计算字段

    在实际工作上遇到的问题: 在订单表中有某项商品是将“订购数量(Quantity)”乘以“单件价格(UnitCost)”等于该项商品的总价(Subtotal). 在数据表中有的列(以下皆改叫为“字段”) ...