(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;
}
#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;
}
相关文章推荐
- 学习正则表达式~~~
- 【swift】15-0529 In-Out参数 函数类型
- hdu1874 畅通工程续
- JAVA 构造方法之间的调用
- 百度地图--根据经纬度定位
- sales order 流程
- 大素数判断_fermat素性测试+Miller-Rabin素性测试
- WEB_猫抓老鼠
- 用Switch控制视图的淡入淡出效果
- 选择器的区别
- 网页版百度地图--根据城市名定位
- 线程池的生命周期和拒绝策略
- Android文字转语音
- @property关键字的使用
- 黑马程序员---IO流的一些总结
- Linux 内核定时器及使用方法
- android利用线程池高效实现异步任务
- 图文详解YUV420数据格式
- RHEL7聚合网络
- 基数排序