华为第三道题目

第三题怎么改都只有37.5,有大佬100AC的吗,要求的输出顺序到底是什么呀?大雾
全部评论
75% +1. 检查半天看不出漏了哪种情况,题名还特意说明 没有非法输入。 最逗的是题目要求按升序,而例子是降序。
点赞 回复 分享
发布于 2017-09-20 21:22
#include <iostream> #include <cstring> #include <string> #include <cstdlib> #include <cstdio> #include <vector> #include <stack> #include <algorithm> #include <set> #include <queue>  #include <cctype> #include <cmath> #include <map> #include <unordered_map> #include <deque> #include <sstream> using namespace std; void replace(string str, const string &bitset, unordered_map<int, int> &record, char nc){     bool flag = false;     int idx = 1;     int i = bitset.size() - 1;     while(i >= 0) {         if(bitset[i] == '1') {             int strIdx = record[idx];             str[strIdx] = nc;             flag = true;         }         --i;         ++idx;     }     if(flag) {         cout << ',' << str;     } } bool nextBitSet(string &bitset) {     const int len = bitset.size();     if(bitset[len-1] == '0') {         bitset[len-1] = '1';         return true;     }     int curIdx = len-1;         while(curIdx >= 0) {         if(bitset[curIdx] == '0') {             bitset[curIdx] = '1';             break;         }         bitset[curIdx--] = '0';     }     if(curIdx < 0) return false;     return true; } int main() {          string str;     char oc, nc;     cin >> str >> oc >> nc;     oc = tolower(oc);     unordered_map<int, int> record;     const int len = str.size();     int idx = 1;     int maxIdx = -1;     bool found = false;     for(int i = len-1; i >= 0; --i) {         char ch = tolower(str[i]);         if(ch == oc) {             found = true;             record[idx++] = i;             maxIdx = (idx > maxIdx? idx : maxIdx);         }     }     if(found) {                 string bitset(maxIdx-1, '0');                 cout << str;         while(nextBitSet(bitset)) {             replace(str, bitset, record, nc);         }         cout << endl;             }else{         cout << str << endl;     }     return 0; } 100%通过
点赞 回复 分享
发布于 2017-09-20 21:19
public class Main {     public static void main(String[] args) {         Scanner s = new Scanner(System.in);         String str = s.nextLine();         String[] strings = str.split(" ");                  TreeSet<String> ts = new TreeSet<String>(new Comparator<String>(){             @Override             public int compare(String o1, String o2) {                                  return o2.compareTo(o1);             }                      });         ts.add(strings[0]);                  new Test3().swap(ts,strings[0],strings[1],strings[2]);                           String last = ts.pollLast();         for (String string : ts) {             System.out.print(string+",");         }         System.out.println(last);                                    s.close();     }     public TreeSet<String> swap(TreeSet<String> ts,String str1,String str2,String str3){         for (int i = 0; i < str1.length(); i++) {             if(str2.equals(str1.charAt(i)+"")){                 StringBuilder sb = new StringBuilder(str1);                 String string = sb.replace(i, i+1, str3).toString();                 ts.add(string);                 swap(ts,string,str2,str3);             }         }         return ts;     } } 不知道对错啊,大神帮看一看
点赞 回复 分享
发布于 2017-09-20 21:18
// 华为第三题.cpp : 定义控制台应用程序的入口点。// include "stdafx.h" include <iostream> include <string> include <vector> using namespace std; int main(){ string input; string src; string dest; cin >> input>>src>>dest; string mytemp; int num = 0; for (int i = 0; i < input.size(); i++) { if (input[i] == src[0]) { num++; mytemp.push_back('0'); } } string stard; for (int i = 0; i < num; i++) { stard.push_back('1'); } vector<string> res; for (int i = 0; i < pow(2, num); i++) { string restemp = input; int cnt = 0; for (int j = 0; j < input.size(); j++) { if (restemp[j] == src[0]) { if (src[0] > dest[0]) { if (mytemp[cnt] == '1') { restemp[j] = dest[0]; } } else { if (mytemp[cnt] == '0') { restemp[j] = dest[0]; } } cnt++; } } res.push_back(restemp); int k = 1; int jinwei = 1; while (jinwei == 1 && mytemp!=stard) { if (mytemp[num - k] == '0') { mytemp[num - k] = '1'; k++; jinwei = 0; } else if (mytemp[num - k] == '1') { mytemp[num - k] = '0'; jinwei = 1; k++; } } } for (int i = 0; i < res.size()-1; i++) { cout << res[i] <<','; } cout << res[res.size() - 1] << endl; cin.get(); cin.get(); return 0; }
点赞 回复 分享
发布于 2017-09-20 21:13
75%的路过。
点赞 回复 分享
发布于 2017-09-20 21:11
没用一题100AC  也是服了
点赞 回复 分享
发布于 2017-09-20 21:11
百分之75路过。。
点赞 回复 分享
发布于 2017-09-20 21:09

相关推荐

04-16 10:27
已编辑
美团_Saas_后端开发
今天周一休息,突发奇想写一篇阶段总结。如题,我已经去了一个和Java彻底毫无关联的行业。曾经我以为自己能在计算机行业发光发热,拿到美团offer那会感觉自己天都亮了。没想到刚入行一年多就当了逃兵。从最开始的热爱到现在一看到代码就厌恶,不知道自己经历了什么。所以我去干什么了?答案是:在成都当了租房销售。上班那会压力大了就念叨着去干租房中介,但是一直下不去这个决心,想着自己学了四年多的计算机知识,终究还是不甘心。终于在某一天准备八股文的时候,看着无数篇和工作内容关系不大的理论知识,那一刻下定决心,决定尝试一下销售行业,也算是给自己一个交代。后面阴差阳错的投了成都自如去当租房管家,没想到面试很顺利,在当天一百多个面试的人里面,我成为了为数不多通过的几个幸运儿之一。目前已经培训通过,正式入职,也开了单,有压力但是每天过得很开心,真心喜欢那种和人交流的感觉,哪怕是最后没有选择找我租房。说这些也是想告诉那些大三,大四正在找Java实习而焦虑的同学:你们现在还年轻,选择很多,容错率也很高,可以尽情去尝试自己喜欢的行业和工作。不用因为某一次的面试没通过或者简历石沉大海而焦虑,更不用因为身边人都在挤编程的独木桥就强迫自己跟风。也算是自己的碎碎念吧,也希望自己能在新的领域取得一点小成就。也祝牛油工作顺利!
沉淀小子:干啥都不丢人啊,生存是必须要的,销售很考验一个人综合素质能力的,好的销售人脉和资源可不比写字楼的白领差啊
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务