hihocoder 1341

解释:
这道题题目还是比较容易理解,就是根据输入的若干个不等式,校验后面输入的数据是否都满足前面的不等式,满足就输出Yes,只要有一个不满足就输出No。如“A<B<=E,3<=E<5”这个两个关系式,对于输入A=1,B=2,E=3肯定满足,因为1<2<=3,3<=3<5。而A=3, B=5,E=10就不满足,因为3<=10<5不成立。

思路:

将一串表达式拆分为每两个数比较大小,读取操作数[字母/数字], 读取运算符[‘<’/‘<=’]

#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <string.h>
#include <ctype.h>
using namespace std; map<char,int> mp; string c[20];
bool used[26]; bool ok(int a, string &op, int b){
if(op=="<") return a<b;
return a<=b;
} int get_val(string &s, int &i){
int res=0;
for(; s[i] && isdigit(s[i]) && !isalpha(s[i]); res*=10, res+=s[i++]-'0');
if(isalpha(s[i])) res=mp[s[i++]];
return res;
} string get_op(string &s, int &i){
string res;
for(; s[i] && ispunct(s[i]); res+=s[i++]);
return res;
} bool check(int n){
int a, b;
string op;
for(int i=0; i<n; i++){
int j=0;
a=get_val(c[i], j);
for(;;){
op=get_op(c[i], j);
if(op=="") break;
b=get_val(c[i], j);
if(!ok(a, op, b)) return false;
a=b;
}
}
return true;
} int main(){
int n, T;
cin>>n;
for(int i=0; i<n; i++){
cin>>c[i];
for(auto x:c[i])
if(isalpha(x)) used[x-'A']=true;
}
int nv=0;
for(int i=0; i<26; i++) nv+=used[i]; for(cin>>T; T--; ){
for(int i=0; i<nv; i++){
char x;
int v;
cin>>x>>v;
mp[x]=v;
}
puts(check(n)?"Yes":"No");
}
}

hihocoder 1341 Constraint Checker【string】的更多相关文章

  1. hihocoder #1341 Constraint Checker

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given a set of constraints like 0<N<=M<=100 and ...

  2. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  3. hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...

  4. 【8.22校内测试】【数学】【并查集】【string】

    今天的t2t3能打出来80分的暴力都好满足啊QwQ.(%%%$idy$ 今天的签到题,做的时候一眼就看出性质叻qwq.大于11的所有数分解合数都可以用4.6.9表示,乱搞搞就可以了. #include ...

  5. C++【string】用法和例子

    /*** * string 基础api复习 * 8 AUG 2018 */ #include <iostream> #include <string> using namesp ...

  6. C++字符串【string】和【char []】操作全攻略

    异想之旅:本人博客完全手敲,绝对非搬运,全网不可能有重复:本人无团队,仅为技术爱好者进行分享,所有内容不牵扯广告.本人所有文章发布平台为CSDN.博客园.简书和开源中国,后期可能会有个人博客,除此之外 ...

  7. 【string】KMP, 扩展KMP,trie,SA,ACAM,SAM,最小表示法

    [KMP] 学习KMP,我们先要知道KMP是干什么的. KMP?KMPLAYER?看**? 正如AC自动机,KMP为什么要叫KMP是因为它是由三个人共同研究得到的- .- 啊跑题了. KMP就是给出一 ...

  8. 【String】String.format(format,args...)的使用解析

    String.format(format,args...)的使用解析 使用kotlin 中使用示例 ================================================== ...

  9. hihoCoder #1498 : Diligent Robots【数学】

    #1498 : Diligent Robots 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There are N jobs to be finished. It t ...

随机推荐

  1. Hdu 5072 Coprime(容斥+同色三角形)

    原题链接 题意选出三个数,要求两两互质或是两两不互质.求有多少组这样的三个数. 分析 同色三角形n个点 每两个点连一条边(可以为红色或者黑色),求形成的三条边颜色相同的三角形的个数反面考虑这个问题,只 ...

  2. .Net并行编程之同步机制

     一:Barrier(屏障同步) 二:spinLock(自旋锁) 信号量  一:CountdownEvent 虽然通过Task.WaitAll()方法也可以达到线程同步的目的. 但是Countdown ...

  3. nlogn LIS模板

    nlogn 模板 最长上升 #include<bits/stdc++.h> using namespace std; ; int n,x,y,a[N],num[N],d[N],len; / ...

  4. 读取Excel中数据

    #region 读取导入Excel数据 /// <summary> /// /// </summary> /// <param name="filename&q ...

  5. JavaScript之函数式编程思想初探

    //result = 3*x + 5; var Mul3 = function(x){ return 3*x; } var Add5 = function(x){ return x + 5; } va ...

  6. Maxwell入门

    1 下载tar包 Download binary distro: https://github.com/zendesk/maxwell/releases/download/v1.19.4/maxwel ...

  7. A - The Water Bowls POJ - 3185 (bfs||高斯消元)

    题目链接:https://vjudge.net/contest/276374#problem/A 题目大意:给你20个杯子,每一次操作,假设当前是对第i个位置进行操作,那么第i个位置,第i+1个位置, ...

  8. F - 回转寿司 (权值线段树)

    题目链接:https://cn.vjudge.net/contest/281960#problem/F 题目大意:中文题目 具体思路:权值线段树,我们每次寻找的是满足 (i<j)   L< ...

  9. Mysql 插入中文错误:Incorrect string value: '\xE7\xA8\x8B\xE5\xBA\x8F...' for column 'course' at row 1

    create table my_user (    id tinyint(4) not null auto_increment,    account varchar(255) default nul ...

  10. android AysncTask使用

    1.继承AysncTask类 例子: class downloadTask extends AsyncTask<Void,Integer,Boolean> 第一个参数是传入的参数 第二个参 ...