题目链接:http://codeforces.com/contest/664/problem/B

B. Rebus
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.

Input

The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer n is positive and doesn't exceed 1 000 000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.

Output

The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise.

If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to n. Follow the format given in the samples.

Examples
input
? + ? - ? + ? + ? = 42
output
Possible
9 + 13 - 39 + 28 + 31 = 42
input
? - ? = 1
output
Impossible
input
? = 1000000
output
Possible
1000000 = 1000000

解题报告:

看到大神们的代码,简直碉堡了。

1、这里的输入要掌控好。

2、思路:先置每个位置为1,记录下加上的数的个数sa,减去的个数sb,这样,p(离目标结果)只差p-n了。

3、根据每个问号前面的符号,自增,达到结果。

#include <cstdio>

using namespace std;

int a[];    ///结果
int v[]; ///记录每个符号 char c[]; ///符号命令 int main()
{
scanf("%s",c); ///输入问号
scanf("%s",c); ///输入符号
int m=; ///?的个数,即要填的数字的个数
int sa=; ///加数的个数
int sb=; ///减数的个数
v[]=; while(c[]!='=')
{
if(c[]=='+')
{
v[++m]=;
sa++;
}
else {
v[++m]=-;
sb++;
}
scanf("%s",c);///输入问号
scanf("%s",c);///输入符号
} int n;
scanf("%d",&n); ///目标结果 for(int i=;i<=m;i++) ///全部填上1
a[i]=; int p=sa-sb; for(int i=;i<=m;i++) ///一个一个处理各个数
{
while((p<n)&&(v[i]==)&&(a[i]<n))
a[i]++,p++;
while((p>n)&&(v[i]==-)&&(a[i]<n))
a[i]++,p--;
} if(p!=n)
{
printf("Impossible\n");
return ;
}
printf("Possible\n");
printf("%d ",a[]); for(int i=;i<=m;i++)
{
if(v[i]==) printf("+ ");
else printf("- ");
printf("%d ",a[i]);
}
printf("= %d\n",n);
}

Codeforces Round #347 (Div.2)_B. Rebus的更多相关文章

  1. Codeforces Round #347 (Div. 2) B. Rebus

    题目链接: http://codeforces.com/contest/664/problem/B 题意: 给你一个等式,把等式左边的问号用1到n(n为等式右边的数)的数填好,使得等式成立 题解: 贪 ...

  2. Codeforces Round #347 (Div. 2)

    unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...

  3. Codeforces Round #347 (Div. 2) C. International Olympiad 找规律

    题目链接: http://codeforces.com/contest/664/problem/C 题解: 这题最关键的规律在于一位的有1989-1998(9-8),两位的有1999-2098(99- ...

  4. Codeforces Round #347 (Div.2)_A. Complicated GCD

    题目链接:http://codeforces.com/contest/664/problem/A A. Complicated GCD time limit per test 1 second mem ...

  5. Codeforces Round #290 (Div. 2) _B找矩形环的三种写法

    http://codeforces.com/contest/510/status/B 题目大意 给一个n*m  找有没有相同字母连起来的矩形串 第一种并查集 瞎搞一下 第一次的时候把val开成字符串了 ...

  6. Codeforces Round #347 (Div. 2) (练习)

    A: 题意:找到[a, b]的最大公约数: 思路:相同时为本身,不同时为1. 套路:碰到水题别想太多: 猜想:两个相邻数,必有一奇一偶,如果偶数有因子3或者其他,奇数可不可能有相同的呢? 枚举一些数后 ...

  7. codeforces Round #347 (Div. 2) C - International Olympiad

    思路:从后往前一位一位的模拟,每次判断一下当前枚举的数是否之间枚举过了.或者当前枚举数过小,小于1989. #include<cstdio> #include<cstring> ...

  8. Codeforces Round #366 (Div. 2)_B. Spider Man

    B. Spider Man time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. Codeforces Round #332 (Div. 2)_B. Spongebob and Joke

    B. Spongebob and Joke time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. hive中解析json数组

    -- hive中解析json数组 select t1.status ,substr(ss.col,,) as col ,t3.evcId ,t3.evcLicense ,t3.evcAddress , ...

  2. mongodb在windows下安装

    下载地址:https://www.mongodb.com/download-center/community 我下载的是zip版本 新建目录:data |_db |_log cmd到所下载的mongo ...

  3. spring boot+jaspersoft实现复杂报表

    1.实现效果: 2.下载 jaspersoft分为社区版和商业版,以下网址是社区版:https://community.jaspersoft.com/community-download

  4. 使用xUnit为.net core程序进行单元测试

      第1部分: http://www.cnblogs.com/cgzl/p/8283610.html 第2部分: http://www.cnblogs.com/cgzl/p/8287588.html ...

  5. WebApi Helper帮助文档 swagger

      http://www.it165.net/pro/html/201602/61437.htmlhttp://www.cnblogs.com/gossip/p/4546630.html       ...

  6. acm刷题序列

    POJ推荐50题 著名的北邮acm训练队推荐50题 https://blog.csdn.net/bat67/article/details/71735012 都是poj上的题 1000:会教会你如何使 ...

  7. 使用EventBus实现兄弟组件之间的通信

    使用EventBus实现兄弟组件之间的通信 需求:为了实现菜单折叠的效果,例如http://blog.gdfengshuo.com/example/work/#/dashboard header组件和 ...

  8. APP测试总结1

    1.安装.卸载测试 安装.卸载测试主要针对编译后源程序生成的APK安装文件 主要测试点: 1).生成的APK文件在真机上可以安装及下载 2).Android手机端的通用安装工具,如:豌豆荚及91助手等 ...

  9. inventor安装失败怎样卸载安装inventor 2015?

    AUTODESK系列软件着实令人头疼,安装失败之后不能完全卸载!!!(比如maya,cad,3dsmax等).有时手动删除注册表重装之后还是会出现各种问题,每个版本的C++Runtime和.NET f ...

  10. java内存区域与内存溢出

    JVM的内存区域划分: jvm的内存区域分为5部分:程序计数器,虚拟机栈,本地方法栈,堆跟方法区. 程序计数器,虚拟机栈,本地方法栈三部分是线程私有的,堆跟方法区是公共的. 1.程序计数器 是一块较小 ...