【2018.4.7】模拟赛之四-ssl2385 猜数【水题】
生活随笔
收集整理的這篇文章主要介紹了
【2018.4.7】模拟赛之四-ssl2385 猜数【水题】
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
正題
大意
給出一些詢(xún)問(wèn)和答案,詢(xún)問(wèn)內(nèi)容包括:
1. 是否大于一個(gè)數(shù)
2. 是否小于一個(gè)數(shù)
3. 是否大于等于一個(gè)數(shù)
4. 是否小于等于一個(gè)數(shù)
這是一個(gè)-10000到10000的數(shù)
求這個(gè)數(shù)的最小值
代碼
#include<cstdio> #include<iostream> using namespace std; int n,x,y,num; char answer,ques[2]; int main() {scanf("%d",&n);x=-10000;y=10000;for (int i=1;i<=n;i++){scanf("%s %d %c",ques,&num,&answer);if (ques[1]=='='){if (ques[0]=='<' && answer=='Y') y=min(y,num);if (ques[0]=='>' && answer=='Y') x=max(x,num);if (ques[0]=='>' && answer=='N') y=min(y,num-1);if (ques[0]=='<' && answer=='N') x=max(x,num+1);}else{if (ques[0]=='<' && answer=='Y') y=min(y,num-1);if (ques[0]=='>' && answer=='Y') x=max(x,num+1);if (ques[0]=='>' && answer=='N') y=min(y,num);if (ques[0]=='<' && answer=='N') x=max(x,num);}}if (y<x) printf("Impossible");else printf("%d",x); }總結(jié)
以上是生活随笔為你收集整理的【2018.4.7】模拟赛之四-ssl2385 猜数【水题】的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【2018.4.7】模拟赛之三-ssl2
- 下一篇: 不堪重负是什么意思 不堪重负的释义