BNUOJ44586(栈模拟)
来源:互联网 发布:pdf.js 获取当前页数 编辑:程序博客网 时间:2024/05/17 04:32
题目链接:http://www.bnuoj.com/v3/problem_show.php?pid=44586
解题思路:
用栈来模拟,考虑时候要注意字母为奇数时才消除。如果当前栈顶为奇数,那么栈顶+1 == s[ i ]的话才可以入栈。如果当前s[ i ]为奇数的话,那么s[ i ] + 1 == 栈顶,s[ i ]才可以消除。
简而言之,我们要考虑的字母 i 要是奇数,并且只有 i 和 i+ 1 才是可消除的。
完整代码:
#include <functional>#include <algorithm>#include <iostream>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>#include <cstring>#include <climits>#include <cassert>#include <complex>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;string s;stack <char> m;int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif std::ios::sync_with_stdio(false); std::cin.tie(0); int T; cin >> T; while(T--) { cin >> s; int len = s.length(); for(int i = 0 ; i < len ; i ++) { if( !m.empty() && ( ( (m.top() - 'a' + 1) % 2 != 0 && m.top() - 'a' + 2 == s[i] - 'a' + 1 ) || ( ( s[i] - 'a' + 1) % 2 != 0 && m.top() - 'a' + 1 == s[i] - 'a' + 2 ) ) ) m.pop(); else m.push(s[i]); } if(m.empty()) { cout << "sad!" << endl; continue; } string t = ""; while( !m.empty() ) { t += m.top(); m.pop(); } int lent = t.length(); for(int i = lent - 1 ; i >= 1 ; i -- ) cout << t[i]; cout << t[0] << endl; s = ""; }}
0 0
- BNUOJ44586(栈模拟)
- POJ_1363_Rails(栈模拟)
- 栈(数组模拟)
- Flipper (栈模拟)
- UVA 101(栈模拟)
- So Easy!!! (栈模拟)
- 模拟栈问题(思路)
- 用链表模拟栈(100)
- 栈模拟
- 模拟栈
- 模拟栈
- 特长生模拟 BIOtech(模拟)
- JS模拟栈(面向对象)
- uva 127 ``Accordian'' Patience(栈+模拟)
- poj 1028 Web Navigation(栈模拟)
- hdu 3887 树状数组(模拟栈)
- 模拟栈操作--(姓名 年龄)
- HDU 1022(栈模拟;暴力搜索)
- PyQt中如何使用界面文件(*.ui,*.qml)
- spring 事务管理文档意译(2/5)
- Android中launcherMode="singleTask"详解<解决home键返回不能出现原界面问题>
- JavaScript中,关于new的那些事
- json和ajax基础运用
- BNUOJ44586(栈模拟)
- UVA 10881 Piotr's Ants
- Ubuntu中compiz 安装与设置
- loadermanager使用解析之个人见解
- 电脑任务管理器里的进程
- Reverse Words in a String
- [2014-12-28]Java笔记_Junit 3.8
- SQLServer 中dm_os_ring_buffers(ring_buffer_connectivity)读取XML
- FragmentpagerAdapter中的getItem方法,在第二次进入承载viewPager的Fragment时不会被调用原因