地铁换乘
来源:互联网 发布:python if false 编辑:程序博客网 时间:2024/04/19 18:10
【】【】【】【】只编写了AB AA BB的情况,BA和AB类似,就不编写了
ps:AB的意思是第一个字符串在A中,第二个字符串在B中
#include <iostream>#include <algorithm>#include <vector>#include <string>#include <math.h>using namespace std;int main(){ string strA[] = {"A1","A2","A3","A4","A5","A6","A7","A8","A9","T1","A10","A11","A12","A13","T2","A14","A15","A16","A17","A18"}; string strB[] = {"B1","B2","B3","B4","B5","T1","B6","B7","B8","B9","B10","T2","B11","B12","B13","B14","B15"}; vector<string>strVecA(strA,strA+20); vector<string>strVecB(strB,strB+17); string str1,str2; while(cin>>str1>>str2) { ///////得到str1,str2在A,B线的位置 vector<string>::iterator it2A,it2B,it1A,it1B,itT1A,itT1B,itT2A,itT2B; it1A = find(strVecA.begin(),strVecA.end(),str1); it1B = find(strVecB.begin(),strVecB.end(),str1); it2A = find(strVecA.begin(),strVecA.end(),str2); it2B = find(strVecB.begin(),strVecB.end(),str2); itT1A = find(strVecA.begin(),strVecA.end(),"T1"); itT1B = find(strVecB.begin(),strVecB.end(),"T1"); itT2A = find(strVecA.begin(),strVecA.end(),"T2"); itT2B = find(strVecB.begin(),strVecB.end(),"T2"); /////////// int pos = 0; if(it1A != strVecA.end() && it2A != strVecA.end())//////AA { pos = abs(it1A - it2A)+1; } else if(it1A != strVecA.end() && it2B != strVecB.end())/////AB { if(it1A < itT2A && it2B < itT2B) { int posT1A = abs(itT1A-it1A); int posT1B = abs(itT1B-it2B); int posT1 = posT1A+posT1B; int posT2A = abs(itT2A-it1A); int posT2B = abs(itT2B-it2B); int posT2 = posT2A+posT2B; pos = ((posT2 > posT1)?(posT1):(posT2)) + 1; } else if(it1A < itT2A && it2B >= itT2B) { if(it1A > itT1A) { int posT2A = abs(itT2A-it1A); int posT2B = abs(itT2B-it2B); int posT2 = posT2A+posT2B; pos = posT2 + 1; } else { int posT1A = abs(itT1A-it1A); int posT1B = abs(itT1B-it2B); int posT1 = posT1A+posT1B - 1; int posT2A = abs(itT2A-it1A); int posT2B = abs(itT2B-it2B); int posT2 = posT2A+posT2B; pos = ((posT2 > posT1)?(posT1):(posT2)) + 1; } } else if(it1A >= itT2A && it2B < itT2B) { if(it2B < itT1B) { int posT1A = abs(itT1A-it1A); int posT1B = abs(itT1B-it2B); int posT1 = posT1A+posT1B; int posT2A = abs(itT2A-it1A); int posT2B = abs(itT2B-it2B); int posT2 = posT2A+posT2B - 1; pos = ((posT2 > posT1)?(posT1):(posT2)) + 1; } else { int posT1A = abs(itT1A-it1A); int posT1B = abs(itT1B-it2B); int posT1 = posT1A+posT1B; int posT2A = abs(itT2A-it1A); int posT2B = abs(itT2B-it2B); int posT2 = posT2A+posT2B; pos = ((posT2 > posT1)?(posT1):(posT2)) + 1; } } else if(it1A >= itT2A && it2B >= itT2B) { //int posT1A = abs(itT1A-it1A); //int posT1B = abs(itT1B-it2B); //int posT1 = posT1A+posT1B; int posT2A = abs(itT2A-it1A);/// int posT2B = abs(itT2B-it2B);/// int posT2 = posT2A+posT2B; pos = posT2 + 1; } } else if(it1B != strVecB.end() && it2B != strVecB.end())//////BB { if((it1B <= itT2B && it1B >= itT1B) || (it2B <= itT2B && it2B >= itT1B)) { pos = abs(it1B - it2B) + 1; } else if((it1B <= itT1B && it2B <= itT1B) || (it1B >= itT2B && it2B >= itT2B)) { pos = abs(it1B - it2B) + 1; } else if((it1B <= itT1B && it2B >= itT2B) || (it2B <= itT1B && it1B >= itT2B)) { pos = abs(it1B - it2B) + 1 - 1; } } else if(it1B != strVecB.end() && it2A != strVecA.end())/////BA { int posT1A = abs(itT1A-it2A); int posT1B = abs(itT1B-it1B); int posT1 = posT1A+posT1B; int posT2A = abs(itT2A-it2A); int posT2B = abs(itT2B-it1B); int posT2 = posT2A+posT2B; pos = ((posT2 > posT1)?(posT1):(posT2)) + 1; } cout<<pos<<endl; str1.clear(); str2.clear(); } system("pause"); return 0;}
0 0
- 地铁换乘
- 地铁换乘
- 地铁换乘
- 地铁换乘
- 地铁换乘
- 蓝桥杯-地铁换乘
- 蓝桥杯地铁换乘问题
- 蓝桥杯-地铁换乘
- 华为地铁换乘问题
- 地铁换乘C++
- 地铁换乘一次进一步修改。
- 华为机试题-地铁换乘
- 地铁换乘最短路径
- 地铁换乘的线路问题
- 地铁采用一次换乘到达sql
- 最短路径之地铁换乘
- 地铁换乘(华为机试样题)
- 华为笔试题——地铁换乘
- AlertDialog实现提示框初体验+自定义对话框
- SHA1算法实现及详解
- 卷积神经网络简介
- 远程登陆linux
- “J.U.C”:Condition (r)
- 地铁换乘
- ScrollView嵌套ListView只显示一行
- HTML语义化
- android环境变量设置
- Centos-yum命令详解
- Codeforces Round #368 (Div. 2) D. Persistent Bookcase (离线算法+lazy标记优化)
- 横竖屏切换,控制每一个Controller的横竖屏状态 控制vc 进入的状态横屏或竖屏
- android布局用GONE隐藏后不能显示的问题
- Linux系统的Zookeeper集群环境搭建