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. How about xlogs are missing and xlogs are deleted

    [postgres@minion1 bin]$ pwd /usr/local/pgtest/bin [postgres@minion1 bin]$ ./pg_ctl -D ../data/ start ...

  2. JAVA-面向对象-特性

    1.封装 1.定义方式 1修饰符class类名 2类名首字母大写 2.类的成员 1属性 成员变量 可以设置默认值 第一个单词首字母小写,后面首字母大写 一般把属性设置成private 提供属性对应的g ...

  3. [原创] 关于quartz (spring 中的任务调度器)时间配置

    1.   CronTrigger时间格式配置说明 CronTrigger配置格式: 格式: [秒] [分] [小时] [日] [月] [周] [年] 序号 说明 是否必填 允许填写的值 允许的通配符 ...

  4. sliverlight 4 vs2010 的安装过程

    今天小白正式开始学习sliverlight 的内容,但是在软件安装的过程中就遇到了问题,查了一下,需要安装对应版本的sdk跟tools,因为在新建项目的时候,可以选择sliverlght,因此,我断定 ...

  5. cookie和session区别

    cookie和session区 session是在服务器端保存用户信息,cookie是在客户端保存用户信息 session保存的是对象,cookie保存的是字符串 session会随回话结束而关闭,c ...

  6. SQL Server面试题

    前几天在博客园上看到一道SQL面试题,sc是表名.老师拿来与同学分享,让大家试做,要求是:查出每科成绩都>=80分的名字,看能写出几种方法.没有主外键,没有关联,脑袋一下子就蒙了.经老师讲解指导 ...

  7. oracle 分区表的维护

    1:添加分区: ALTER TABLE SALES ADD PARTITION P3 VALUES LESS THAN(TO_DATE('2003-06-01','YYYY-MM-DD')); SAL ...

  8. Oracle数据类型总结

    一 字符串类型 1.1:CHAR类型 CHAR(size [BYTE | CHAR]) CHAR类型,定长字符串,会用空格填充来达到其最大长度.非NULL的CHAR(12)总是包含12字节信息.CHA ...

  9. JFreeChart在制作折线图

    JFreeChart在制作折线图的时候可以使用两种不同的方式 package Line; import java.awt.Color; import java.awt.Font; import org ...

  10. ubuntu下配置SVN服务器

    自己买的阿里云服务器.可是我老感觉没有SVN上传代码下载代码太不方便!决定配置个SVN服务器! 1.安装Subversion $ sudo apt-get install subversion $ s ...