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 collections读书笔记(9)collection框架总览(2)

    框架算法: 1)collection接口 add()  Adds an element to the collection.addAll()  Adds a collection of element ...

  2. OLTP与OLAP的差异

    OLTP与OLAP的差异 系统类型 OLTP(在线交易系统) OLAP(联机分析系统),DW(数据仓库) 数据来源 操作数据,OLTP通常是原始性数据源 联合型数据:OLAP数据来源于其他OLTP系统 ...

  3. 搭建企业cacti服务器

    搭建企业cacti服务器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 今天搭建了cacti,为了方便监控我的交换机~因为查了很多zabbix的资料关于监控交换机的教程~我都屡屡失 ...

  4. 转:python webdriver API 之上传文件

    文件上传操作也比较常见功能之一,上传功能操作 webdriver 并没有提供对应的方法,关键上传文件的思路.上传过程一般要打开一个系统的 window 窗口,从窗口选择本地文件添加.所以,一般会卡在如 ...

  5. paper 69:Haar-like矩形遍历检测窗口演示Matlab源代码[转载]

    Haar-like矩形遍历检测窗口演示Matlab源代码 clc; clear; close all; % Haar-like特征矩形计算 board = 24 % 检测窗口宽度 num = 24 % ...

  6. angular 依赖注入

    依赖注入    依赖注入(DI)是一个经典的设计模式, 主要是用来处理组件如何获得依赖的问题.关于DI,推荐阅读Martin Flower的文章(http://martinfowler.com/art ...

  7. RMAN备份演练初级篇

    前面我们已经知道了如何进入rman,以及rman的一些基本命令,相信大家定会觉着rman操作的简单,事实也确实如此,但万不要因此小视rman的强大,简单往往意味着灵活,灵活对于那些有心人则意味着主动权 ...

  8. IUS通过PLI产生fsdb波形

    IUS通过PLI接口来调用系统函数,产生fsdb波形,再由verdi来debug. 要调用fsdbDumpfile和fsdbDumpvars,需要在testcase的shell(或.cshrc等)中设 ...

  9. css3颜色渐变

    从上到下的线性渐变: #grad {  background: -webkit-linear-gradient(red, blue); /* Safari 5.1 - 6.0 */  backgrou ...

  10. 关于Python中数据对象的可变性

    先贴上Python官网中对数据模型描述的几段话.(在python官网的 语言参考>>数据模型 那部分) Every object has an identity, a type and a ...