Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 关于题目意思

Posted by yygy at 2012-10-12 16:49:48 on Problem 2338
```/*题目意思太难理解。

xxx#yy##zz#是合法的。

*/
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAX=88;
char s[MAX];
char num[MAX][MAX];
int getval(char x)
{
if(x>='0'&&x<='9')return x-'0';
return x-'a'+10;
}
int getb(char s[],int b)
{
int i,ret=0;
for(i=0;s[i]&&ret<=16;i++)
{
int tmp=getval(s[i]);
if(tmp>=b)return -1;//超出权值，返回-1
ret=ret*b+tmp;
}
if(ret>16)return 17;
return ret;
}
int main()
{
int T;

scanf("%d",&T);
while(T--)
{
scanf("%s",s);
int i;

//判断是否只含数字井号和a到f的字符
for(i=0;s[i];i++)
{
if(s[i]=='#')continue;
if(s[i]>='0'&&s[i]<='9')continue;
if(s[i]>='a'&&s[i]<='f')continue;
break;
}
if(s[i])
{
puts("no");
continue;
}
//end

int n=0,j;
int cnt=0,len;

//数#号个数
for(i=0;s[i];i++)
{
if(s[i]=='#')cnt++;
}
len=strlen(s);

//把里面的数字分解出来
for(i=0;i<len;i++)
{
if(s[i]!='#')
{
j=0;
while(i<len&&s[i]!='#')
{
num[n][j++]=s[i];
i++;
}
if(s[i]!='#')i--;
num[n][j]=0;
n++;
}
}
//end

//判断#号个数，
if(cnt!=(n-1)*2)
{
puts("no");
continue;
}

//判断#号匹配
if(cnt>0)
{

if(s[i-1]!='#')
{
puts("no");
continue;
}
else if(s[0]=='#')
{
puts("no");
continue;
}
len=strlen(s);
for(i=0;i+2<len;i++)
{
if(s[i]=='#'&&s[i+1]=='#'&&s[i+2]=='#')
{
break;
}
}
if(i+2<len)
{
puts("no");
continue;
}

for(i=0;i+1<len;i++)
{
if(s[i]=='#'&&s[i+1]=='#')
{
cnt-=2;
}
}
if(cnt!=2)
{
puts("no");
continue;
}
}
//end
int b;

if(n==0)
{
puts("yes");
continue;
}

//只能一个数字
if(n==1)
{
//直接转化
b=getb(num[0],10);
if(b==-1)
{
puts("no");
}
else
{
puts("yes");
}
continue;
}

b=getb(num[0],10);
//判断权值是否合法
if(b>16||b<2)
{
puts("no");
continue;
}

//将后面的转化成对应的数字
for(i=1;i+1<n;i++)
{
b=getb(num[i],b);
if(b==-1)break;
if(b>16||b<2){break;}
}
if(i+1<n)
{
puts("no");
continue;
}

//判断最后一个数字的每一位是否超出权值
for(j=0;num[i][j];j++)
{
int tmp=getval(num[i][j]);
if(tmp>=b)break;
}
if(num[i][j]!=0)
{
puts("no");
}
else puts("yes");
}
return 0;
}
/*

*/

```

Followed by: