Black birds skimmed the sky, I stood in the city, watching time burn into ashes, clattering...
Topic Description
There are many traffic intersections in Beibei's city, 26 of which are always in traffic jams during rush hours, which seriously affects the citizens'travel. So the traffic management department has developed a batch of robotic traffic policemen to command these 26 traffic intersections, but they need an automated command system to command the operation of robots. The task is assigned to Beibei, whose design is as follows.
Capital letters A, B and B, respectively. Z means these 26 intersections and sends these robots to traffic intersections to assist in directing traffic according to the following rules:
1. Two robots are dispatched at a time;
2. When the two robots have the same letters in their names, they go to the corresponding traffic intersections to direct traffic; when there are more than one letters in the same place, the two robots need to patrol these intersections in alphabetical dictionary order.
3. When the names of the two robots do not have the same letters, the dispatch instructions of the traffic police department are invalid (Wu Xiao).
Assuming that the names of these robots are all in capital letters, please write a program to help Beibei complete the traffic command system.
input
Line 1 enters the name of the first robot (no longer than 250 in length).
Line 2 enters the name of the second robot (no longer than 250 in length).
output
1. When the robot can't be dispatched, output "Wu Xiao" in the first line.
2. When two robots command traffic on the intersection, they output "ZhiHui" in the first line and the number of the intersection in the second line.
3. When two robots patrol an intersection, they output "XLuo" in the first line, the number of patrol routes in the second line and the patrol routes in the third line.
sample input
Duplicate sample data
OPEN CLOSE
sample output
XLuo 2 E-O
This question does not want to say, the first code is correct, but why the second code is not right??? (iv) What's more, if you change cin and cout in the first code to scanf, is printf wrong?
#include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cctype> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; int main() { string a,b; cin>>a>>b; set<char>P; int L1=a.length(); int L2=b.length(); for(int i=0; i<L1; i++) for(int j=0; j<L2; j++) if(a[i]==b[j]) P.insert(a[i]); set<char>::iterator it; int num=P.size(); if(num==0) cout<<"WuXiao"<<endl; else if(num==1) { cout<<"ZhiHui"<<endl; for(it=P.begin(); it!=P.end(); it++) cout<<*it<<endl; } else { cout<<"XLuo"<<endl; cout<<num<<endl; int flag=0; for(it=P.begin(); it!=P.end(); it++) { if(flag) cout<<"-"; flag=1; cout<<*it; } cout<<endl; } return 0; }
#include <map> #include <set> #include <list> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cctype> #include <cstdio> #include <bitset> #include <string> #include <vector> #include <complex> #include <cstring> #include <iomanip> #include <iostream> #include <algorithm> #include <functional> #define inf 0x3f3f3f3f typedef long long ll; using namespace std; string s1,s2; set<char>p1,p2,p; int main() { cin>>s1; cin>>s2; int i,l1=s1.length(),l2=s2.length(); for(i=0; i<l1; i++) { p1.insert(s1[i]); p.insert(s1[i]); } for(i=0; i<l2; i++) { p2.insert(s2[i]); p.insert(s2[i]); } int sum=p1.size()+p2.size(); int sump=p.size(); int sumz=sum-sump; // cout<<sum<<endl<<sump<<endl; // Set < char >:: iterator dd; // Define forward iterator // for(dd = p1.begin(); dd != p1.end(); dd++) // cout << *dd<< " "; // cout<<endl; // for(dd = p2.begin(); dd != p2.end(); dd++) // cout << *dd << " "; // cout<<endl; // for(dd = p.begin(); dd != p.end(); dd++) // cout << *dd << " "; if(sumz==0) printf("WuXiao"); if(sumz>=1) { int flag=1; if(sumz==1) printf("ZhiHui\n"); else { printf("XLou\n"); printf("%d\n",sumz); } set<char>::iterator dd; set<char>::iterator ss; //Define forward iterators for(dd = p1.begin(); dd != p1.end(); dd++) { for(ss=p2.begin(); ss!=p2.end(); ss++) { if(*dd==*ss) { if(flag==1) { printf("%c",*dd); flag=0; } else printf("-%c",*dd); } } } } printf("\n"); return 0; }