题目链接:http://poj.org/images/20111210problems.pdf
哎,WA了十几次,始终未AC,放弃了。实在看不出BUG在哪里。写个bog纪念一下。。。。。。
CODE:
#include <iostream>
#include <string.h>
using namespace std;
int m,n,s,k;
string str;
int cnt;
bool judge(string ss){
for(int i=0;i<ss.size();i++){
if(ss[i]=='.'){
if(cnt&&cnt!=s)
return false;
}
else
cnt++;
}
if(cnt&&cnt!=s)
return false;
return true;
}
int main()
{
while(cin>>m>>n>>s>>k>>str){
cnt=0;
bool flag=false;
for(int i=0;i<str.size();i++)
if(str[i]=='*')
flag=true;
if(!flag){
if(n==s){
if(m-k>=s&&k>s)
cout<<"Ambiguous"<<endl;
else if(m-k>=s||k>s)
cout<<"Unique"<<endl;
else
cout<<"Impossible"<<endl;
}
else if(n>s){
if(m-k>=s||k>s)
cout<<"Ambiguous"<<endl;
else
cout<<"Impossible"<<endl;
}
else
cout<<"Impossible"<<endl;
str.erase();
continue;
}
if(judge(str)&&(m-k>=s-1&&k>=s)&&s>1)
cout<<"Ambiguous"<<endl;
else if(judge(str)&&(m-k>=s-1||k>=s||s==1||s==m))
cout<<"Unique"<<endl;
else
cout<<"Impossible"<<endl;
str.erase();
}
return 0;
}