003連接:https://www.nowcoder.com/questionTerminal/0a92c75f5d6b4db28fcfa3e65e5c9b3f
來源:牛客網
ios
輸入兩手牌,兩手牌之間用「-」鏈接,每手牌的每張牌以空格分隔,「-」兩邊沒有空格,如4 4 4 4-joker JOKER。
輸出兩手牌中較大的那手,不含鏈接符,撲克牌順序不變,仍以空格隔開;若是不存在比較關係則輸出ERROR。
4 4 4 4-joker JOKER
joker JOKER
1 連接:https://www.nowcoder.com/questionTerminal/0a92c75f5d6b4db28fcfa3e65e5c9b3f 2 來源:牛客網 3 4 //「輸入每手牌多是個子,對子,順子(連續5張),三個,炸彈(四個)和對王中的一種, 5 //不存在其餘狀況,由輸入保證兩手牌都是合法的,順子已經從小到大排列「 6 //這句規則讓牌面類型的肯定和大小的比較直接能夠轉換爲牌個數的比較了,這是解決測試問題的捷徑! 7 //因此必定要善於利用題目已知條件!!! 8 #include <iostream> 9 #include <string> 10 #include <algorithm> 11 using namespace std; 12 int main(){ 13 string line; 14 while(getline(cin,line)){ 15 if(line.find("joker JOKER")!=-1) 16 cout<<"joker JOKER"<<endl; 17 else{ 18 int dash=line.find('-'); 19 string car1=line.substr(0,dash); 20 string car2=line.substr(dash+1); 21 int c1=count(car1.begin(),car1.end(),' '); 22 int c2=count(car2.begin(),car2.end(),' '); 23 string first1=car1.substr(0,car1.find(' ')); 24 string first2=car2.substr(0,car2.find(' ')); 25 string str="345678910JQKA2jokerJOKER"; 26 if(c1==c2){ 27 if(str.find(first1)>str.find(first2)) 28 cout<<car1<<endl; 29 else 30 cout<<car2<<endl; 31 }else 32 if(c1==3) 33 cout<<car1<<endl; 34 else if(c2==3) 35 cout<<car2<<endl; 36 else 37 cout<<"ERROR"<<endl; 38 } 39 } 40 }
連接:https://www.nowcoder.com/questionTerminal/67df1d7889cf4c529576383c2e647c48
來源:牛客網
一行或多行字符串。每行包括帶路徑文件名稱,行號,以空格隔開。
文件路徑爲windows格式
如:E:\V1R2\product\fpgadrive.c 1325
將全部的記錄統計並將結果輸出,格式:文件名代碼行數數目,一個空格隔開,如: fpgadrive.c 1325 1
結果根據數目從多到少排序,數目相同的狀況下,按照輸入第一次出現順序排序。
若是超過8條記錄,則只輸出前8條記錄.
若是文件名的長度超過16個字符,則只輸出後16個字符
E:\V1R2\product\fpgadrive.c 1325
fpgadrive.c 1325 1
1 #include<iostream> 2 #include<string> 3 #include<vector> 4 #include<algorithm> 5 using namespace std; 6 7 bool compare(pair<string,int> a,pair<string,int> b) 8 { 9 return a.second > b.second; 10 } 11 int main() 12 { 13 string input, str; 14 vector<pair<string, int>> error; 15 while (getline(cin, input)) 16 { 17 if (input.size()==0) break; 18 int pos = input.rfind('\\'); 19 str = input.substr(pos + 1); 20 error.push_back(make_pair(str,1)); 21 for (int i = 0; i < (error.size() - 1);i++) 22 { 23 if (error[i].first == str) 24 { 25 error[i].second++; 26 error.pop_back(); 27 break; 28 } 29 } 30 31 } 32 33 stable_sort(error.begin(),error.end(),compare); 34 35 int idx = 0; 36 while (idx < 8 && idx<error.size()) 37 { 38 string check = error[idx].first; 39 int t = check.find(' '); 40 if (t>16) 41 error[idx].first.erase(0,t-16); 42 //或者 error[idx].first=error[idx].first.substr(t - 16); 43 cout << error[idx].first << " " << error[idx].second << endl; 44 idx++; 45 46 } 47 48 return 0; 49 }