您的位置:首页 > 其它

(4915)HDU

2015-05-29 20:43 239 查看
#include<iostream>

#include<cstdio>

#include<string.h>

#include<cstring>

#include<string>

#include<stack>

#include<set>

#include<algorithm>

#include<cmath>

#include<vector>

#include<map>

#define LOCAL

#define ll long long

#define lll unsigned long long

#define MAX 1000009

#define eps 1e-8

#define INF 0x7fffffff

#define mod 1000000007

using namespace std;

/*

题意:问你是否改变?的情况下,是否匹配,多重匹配还是单一匹配

想法:先去掉不可能的,然后先把?变成左括号,然后在变成右括号。

ps:http://m.blog.csdn.net/blog/u010709592/38400419

*/

char str[MAX];

char tmp[MAX];

char Stack[MAX];

bool judge(int len)

{

int top = - 1;

for(int i = 0; i<len; i++)

{

if(tmp[i]=='(')

{

top++;

}

else

{

if(top==-1) return false;

else

top--;

}

}

if(top==-1)return true;

else return false;

}

int main()

{

while(scanf("%s",str)!=EOF)

{

int len = strlen(str);

if(len&1)

{

puts("None");

continue;

}

int l = 0;

int r = 0;

int cntl = 0;

int cntr = 0;

for(int i = 0; i<len; i++)

{

if(str[i]=='(') l++;

else if(str[i]==')') r++;

}

cntl = (len - 2*l)/2;//计算有多少个问号变成左括号

cntr = (len - 2*r)/2;//计算有多少个右括号变成右括号

int t = cntl;

int posl = -1;

int posr = -1;

for(int i = 0; i<len; i++)

{

if(str[i] == '?')

{

if(t>0)

{

tmp[i] = '(';

t--;

if(t==0) posl = i;//最后一个变成左括号的问号的位置

}

else

{

tmp[i] = ')';

if(posr==-1)

posr = i;//最后一个变成右括号的问号的位置

}

}

else

tmp[i] = str[i];

}

if(!judge(len))

{

puts("None");

}

else

{

if(posl == -1 || posr == -1)

{

puts("Unique");

}

else

{

swap(tmp[posl],tmp[posr]);

if(judge(len))puts("Many");

else puts("Unique");

}

}

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: