hihocoder 1341 Constraint Checker【string】
解释:
这道题题目还是比较容易理解,就是根据输入的若干个不等式,校验后面输入的数据是否都满足前面的不等式,满足就输出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】的更多相关文章
- hihocoder #1341 Constraint Checker
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given a set of constraints like 0<N<=M<=100 and ...
- hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)
#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- 【8.22校内测试】【数学】【并查集】【string】
今天的t2t3能打出来80分的暴力都好满足啊QwQ.(%%%$idy$ 今天的签到题,做的时候一眼就看出性质叻qwq.大于11的所有数分解合数都可以用4.6.9表示,乱搞搞就可以了. #include ...
- C++【string】用法和例子
/*** * string 基础api复习 * 8 AUG 2018 */ #include <iostream> #include <string> using namesp ...
- C++字符串【string】和【char []】操作全攻略
异想之旅:本人博客完全手敲,绝对非搬运,全网不可能有重复:本人无团队,仅为技术爱好者进行分享,所有内容不牵扯广告.本人所有文章发布平台为CSDN.博客园.简书和开源中国,后期可能会有个人博客,除此之外 ...
- 【string】KMP, 扩展KMP,trie,SA,ACAM,SAM,最小表示法
[KMP] 学习KMP,我们先要知道KMP是干什么的. KMP?KMPLAYER?看**? 正如AC自动机,KMP为什么要叫KMP是因为它是由三个人共同研究得到的- .- 啊跑题了. KMP就是给出一 ...
- 【String】String.format(format,args...)的使用解析
String.format(format,args...)的使用解析 使用kotlin 中使用示例 ================================================== ...
- hihoCoder #1498 : Diligent Robots【数学】
#1498 : Diligent Robots 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 There are N jobs to be finished. It t ...
随机推荐
- 机器学习课程-第8周-聚类(Clustering)—K-Mean算法
1. 聚类(Clustering) 1.1 无监督学习: 简介 在一个典型的监督学习中,我们有一个有标签的训练集,我们的目标是找到能够区分正样本和负样本的决策边界,在这里的监督学习中,我们有一系列标签 ...
- C++字符串(srtring)反转
对称平方数 题目描述 打印所有不超过n(n<256)的,其平方具有对称性质的数.如11*11=121. 分析: 1.首先使用函数to_string将int转化为string: 2.然后将字符串反 ...
- Python生成唯一id的方法
1. uuid import uuid def create_uid(): return str(uuid.uuid1()) if __name__ == '__main__': print(type ...
- C# 一般处理程序生成验证码
using System; using System.Collections; using System.Data; using System.Linq; using System.Web; usin ...
- Spring源码解读
beanfactory https://www.cnblogs.com/lspz/p/6244948.html requestmapping https://blog.csdn.net/u012557 ...
- Go 语言读书笔记
Go语言的设计理念很明确,就是将动态类型语言的编程容易度和静态类型语言的安全效率结合起来. Go语言,又称Golang,是Google开发的一款静态强类型.编译型.并发型,并具有垃圾回收机制的 ...
- C - Little Jumper (三分)
题目链接:https://cn.vjudge.net/contest/281961#problem/C 题目大意:青蛙能从一个点跳到第三个点,如图,需要跳两次.问整个过程的最大起跳速度中的最小的. 具 ...
- js获取当前日期时间“yyyy-MM-dd HH:MM:SS”
获取当前的日期时间 格式“yyyy-MM-dd HH:MM:SS” 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 function getNowFormatDat ...
- 11、Logback日志框架介绍和SpringBoot整合实战 2节课
1.新日志框架LogBack介绍 简介:日志介绍和新日志框架Logback讲解 1.常用处理java的日志组件 slf4j,log4j,logback,common-logging 等 ...
- ODPS
ODPS 功能之概述篇 原文 http://blog.aliyun.com/2962 主题 SQL 概述 ODPS是阿里云基于自有的云计算技术研发一套开放数据处理服务(Open Data Proce ...