【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

把所有的问号都改成'1'
然后会发现只有+0?这种情况
需要把?改成+.
看看这样的0后面的1是不是由问号改过来的就好了。是的话
再把这个1变成'+'就好。
判断一下首尾有符号的情况。
以及连续两个出现符号的情况。

【代码】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define lson l,mid,rt<<1
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)
#define res(x) scanf("%s",x)
#define rson mid+1,r,rt<<1|1
using namespace std; const double pi = acos(-1);
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0}; const int N = 1e5;
bool flag[1000];
string s; bool issign(char key){
if (key=='+' || key=='*') return true;
return false;
} bool isnumber(char key){
if (key>='0' && key<='9')
return true;
return false;
} bool ok(){
memset(flag,0,sizeof flag);
int len = s.size();
for (int i = 0;i < len;i++)
if (s[i]=='?')
flag[i] = 1;
for (int i = 0;i < len;i++)
if (s[i]=='?')
s[i] = '1';
for (int i = 0;i < len;i++){
if (s[i]=='0' && (i==0 || !isnumber(s[i-1])) && i<len-1 && isnumber(s[i+1])){
//s[i]是一个前导0
if (!flag[i+1]) return false;
s[i+1] = '+';
} }
if (issign(s[0]) || issign(s[len-1])) return false;
for (int i = 0;i < len-1;i++)
if (issign(s[i]) && issign(s[i+1]))
return false;
return true;
} int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
//freopen("D:\\out.txt","w",stdout);
#endif
ios::sync_with_stdio(0),cin.tie(0);
int T;
cin >> T;
while (T--){
cin >> s;
if (!ok()){
cout<<"IMPOSSIBLE"<<endl;
}else{
cout<<s<<endl;
}
}
return 0;
}

【hdu 6342】Expression in Memories的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. Android学习笔记(8):ViewGroup类

    A ViewGroup is a special view that can contain other views (called children.) The view group is the  ...

  2. HDU1846(巴什博奕)

    Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  3. cocos2d-x-3.1 NotificationCenter (coco2d-x 学习笔记八)

    在这里分享记录自己的学习NotificationCenter时候的代码,这里用NotificationManager进行管理使用NotificationCenter. NotificationMana ...

  4. iOS- &quot;unacceptable content-type: text/plain&quot;等content-type bug解决方式

    常常在使用AFN的时候会出现content-type错误,缺少请求类型,比方"unacceptable content-type: text/plain" 解决方法: 1.在网络请 ...

  5. oc14--匿名对象

    // // main.m // 匿名对象 #import <Foundation/Foundation.h> #import "Person.h" #import &q ...

  6. c17---指针

    // // main.c // 指针基本概念 #include <stdio.h> // 基本数据类型作为函数的参数是值传递, 在函数中修改形参的值不会影响到外面实参的值 void cha ...

  7. Swift - 可编辑表格样例(可直接编辑单元格中内容、移动删除单元格)

    (本文代码已升级至Swift3)   本文演示如何制作一个可以编辑单元格内容的表格(UITableView). 1,效果图 (1)默认状态下,表格不可编辑,当点击单元格的时候会弹出提示框显示选中的内容 ...

  8. 2017-3-10 leetcode 229 238 268

    今天登陆leetcode突然发现531被锁了,有种占了便宜的感觉哈哈哈! ================================================ leetcode229 Ma ...

  9. C++_class_powerpoint_1.1

    Types and Declarations Boolean Type bool type – boolean , logic type bool literal – true, falseint a ...

  10. [.Net] 导出Excel中身份证等数字串的解决方式

    public static void DataTableToExcel(System.Data.DataTable dtData, String FileName) { GridView dgExpo ...