小米第一题只出现一次的数,跪求解答

通过33%

全部评论
赛马网是个超级垃圾的系统,怀念牛客系统
点赞 回复 分享
发布于 2018-09-20 20:46
顺便求一下第二题,扩容水池的做法
点赞 回复 分享
发布于 2018-09-20 20:48
#include <iostream> #include <bits/stdc++.h> using namespace std; map<int, int> count_map; map<string, int> line2num; vector<string> lines; int main() { string line; while (cin >> line) { if (line == "END") { break; } int pos = line.find('#'); string base = line.substr(0, pos); string num = line.substr(pos + 1); int new_num = stoi(num, 0, stoi(base)); count_map[new_num]++; line2num[line] = new_num; lines.push_back(line); } bool find = false; for (auto line : lines){ int num = line2num[line]; if (count_map[num] == 1) { cout << line << endl; find = true; } } if(find == false) cout << "None" << endl; return 0; }
点赞 回复 分享
发布于 2018-09-20 21:55
输出的顺序问题,要用linkedmap有序字典
点赞 回复 分享
发布于 2018-09-20 21:52
蛋哥啊
点赞 回复 分享
发布于 2018-09-20 21:50
``` # -*- coding: utf-8 -* result = [] result1=[] result2=[] result3=[] while True: a=raw_input() if a =='END': set = set(result1) for i in set: if result1.count(i) == 1: result2.append(i) # 转换且为1的数 for i in result2: result3.append(result[result1.index(i)]) for i in result3: print i break b=a.split('#') result1.append(int(b[1],int(b[0]))) #转换 result.append(a) #未转化 # 10#15 # 4#32 # 4#33 # 8#17 # END ```
点赞 回复 分享
发布于 2018-09-20 21:48
AC了 package xiaomi; import java.util.*; public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in);                  List<Long> list_all_nums = new ArrayList<Long>();         List<String> inputs = new ArrayList<String>();         do{             String input = sc.nextLine();             inputs.add(input);             if("END".equals(input)){                 break;             }             String[] strs = input.split("#");             long k = Long.parseLong(strs[1], Integer.parseInt(strs[0]));             list_all_nums.add(k);         }while(true);         int count = 0;         for (int i = 0; i < list_all_nums.size(); i++) {             List tmp = new ArrayList<>(list_all_nums);             tmp.remove(i);             Set set = new HashSet<>(tmp);             int size = set.size();             set.add(list_all_nums.get(i));             if(set.size() != size){                 System.out.println(inputs.get(i));                 count++;             }         }         if(count==0){             System.out.println("None");         }              }      }
点赞 回复 分享
发布于 2018-09-20 20:57
import java.util.*; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); HashMap<Integer,String> hashMap = new HashMap<Integer, String>(); HashSet<Integer> hashSet = new HashSet<>(); List<Integer> list = new ArrayList<Integer>(); while(true) { String str = scanner.nextLine(); if(str.contains("#")) { String[] strings = str.split("#"); int n = Integer.parseInt(strings[0]); int res = resolveNum(n,strings[1]); // 如果已经存在这个数,则将这个数加入到set中 if(hashMap.containsKey(res)) { hashSet.add(res); } // 将所有的结果和 原字符串加入到map和list中 hashMap.put(res, str); list.add(res); } else { break; } } // 标记是不是None boolean flag = false; // 如果set中没有这个数,说明这个数需要输出。 list保证顺序。 for(int x : list) { if(!hashSet.contains(x)) { flag = true;   System.out.println(hashMap.get(x)); } } if(!flag) { System.out.println("None"); } } // 用来转化成10进制   private static int resolveNum(int n, String m) { int res =1; int cnt = 1; char[] chars = m.toCharArray(); for(int i =m.length()-1;i>=0;i--) { int tmp; if(chars[i] > '9') { chars[i] = Character.toUpperCase(chars[i]);   tmp = (int)(chars[i] - 'A') + 10;   } else { tmp = (int)(chars[i] - '0');   } res += tmp*cnt;   cnt*=n;   } return res; } }
点赞 回复 分享
发布于 2018-09-20 20:55
33%的,注意是小写字母,可以结题了
点赞 回复 分享
发布于 2018-09-20 20:51
这个题有两个坑点,第一,异数可能不唯一;第二,如果不唯一,那么按照输入的顺序打印出来就好....
点赞 回复 分享
发布于 2018-09-20 20:49
78
点赞 回复 分享
发布于 2018-09-20 20:49
map+vector+sort
点赞 回复 分享
发布于 2018-09-20 20:47
public class Main {     public static void main(String[] args){         ArrayList<String> res = new ArrayList<>();         ArrayList<Integer> list = new ArrayList<>();         boolean flag = false;         Scanner sc = new Scanner(System.in);         while(sc.hasNextLine()){             String str = sc.nextLine();             res.add(str);             if(str.equals("END")) break;             String[] s = str.split("#");             int n = Integer.parseInt(s[0]);             int m = Integer.parseInt(s[1], n);             list.add(m);         }         for(int i = 0; i < list.size(); i++){             int m = list.get(i);             if(list.lastIndexOf(m) == list.indexOf(m)){                 System.out.println(res.get(i));                 flag = true;             }         }         if(!flag) System.out.println("None");     } }
点赞 回复 分享
发布于 2018-09-20 20:47
#include<iostream> #include<vector> #include<string> #include<map> using namespace std; int func(string str) {     int count = 0,i;     //bool flag = false;     for ( i = 0; i<str.size(); i++)     {         if (str[i] == '#')             break;         count = count * 10 + str[i] - '0';     }     int num = 0;     for (i = i+1; i<str.size(); i++)     {         if(str[i]>='0'&&str[i]<='9')             num = num * count + str[i] - '0';         else             num = num * count + str[i] - 'a'+10;     }     return num; } int main() {     string str;     vector<int> data;     vector<string> data_str;     map<int, int> flag;     while (cin >> str)     {         if (str == "END")             break;         else         {             int num = func(str);             data.push_back(num);             data_str.push_back(str);             flag[num]++;         }     }     bool f = false;     for (int i = 0; i<data.size(); i++)     {         if (flag[data[i]] <= 1)         {             cout << data_str[i] << endl;             f = true;         }     }     if (!f)         cout << "None" << endl;     return 0; }
点赞 回复 分享
发布于 2018-09-20 20:46
package Mi.Exam1; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; class StrNum{ String s; int value; public StrNum(int value, String s) { this.s = s; this.value = value; } } public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); ArrayList<StrNum> list = new ArrayList<>(); HashMap<Integer,Integer> map = new HashMap<>(); while(in.hasNext()) { String str = in.nextLine(); if(!str.equals("END")) { String[] num = str.split("#"); int n = Integer.parseInt(num[0]); int value = Integer.parseInt(num[1], n); StrNum temp = new StrNum(value, str); map.put(value, map.containsKey(value) ? map.get(value)+1 : 1); list.add(temp); } else { break; } } in.close(); boolean isExist = false; for(StrNum strNum : list) { if(map.get(strNum.value) == 1) { isExist = true; System.out.println(strNum.s); } } if(!isExist) { System.out.println("None"); } } }
点赞 回复 分享
发布于 2018-09-20 20:45
package main import ( "fmt" "strconv" "strings" ) var l map[byte]int func init() { l = make(map[byte]int) l['0'] = 0 l['1'] = 1 l['2'] = 2 l['3'] = 3 l['4'] = 4 l['5'] = 5 l['6'] = 6 l['7'] = 7 l['8'] = 8 l['9'] = 9 l['A'] = 10 l['B'] = 11 l['C'] = 12 l['D'] = 13 l['E'] = 14 l['F'] = 15 l['a'] = 10 l['b'] = 11 l['c'] = 12 l['d'] = 13 l['e'] = 14 l['f'] = 15 } func main() { var n int var m string var input string inputList := make([]string, 0) numList := make([]int, 0) for { fmt.Scan(&input) if input == "END" { break } index := strings.Index(input, "#") n, _ = strconv.Atoi(input[:index]) m = input[index+1:] inputList = append(inputList, input) numList = append(numList, ntot(n, m)) } shit := make(map[int]int) for i := range numList { if _, ok := shit[numList[i]]; ok { shit[numList[i]]++ } else { shit[numList[i]] = 1 } } number := 0 for i := range numList { if shit[numList[i]] == 1 { fmt.Println(inputList[i]) number++ } } if number == 0 { fmt.Println("None") } fmt.Println(numList) } func ntot(n int, m string) (ans int) { for i := 0; i < len(m); i++ { ans += l[m[len(m)-1-i]] * wtf(n, i) } return } func wtf(n, i int) int { ans := 1 for j := 1; j <= i; j++ { ans *= n } return ans }
点赞 回复 分享
发布于 2018-09-20 20:45
10分钟写完,调试50分钟死活过不去
点赞 回复 分享
发布于 2018-09-20 20:45
数据有问题,使用Integer.valueof()就runtimError 百分17,不使用上面的函数换成字符串一个一个字符读就wrong answer 百分33
点赞 回复 分享
发布于 2018-09-20 20:44
奥义,双重for循环
点赞 回复 分享
发布于 2018-09-20 20:43
17%
点赞 回复 分享
发布于 2018-09-20 20:42

相关推荐

程序员小假:人才
点赞 评论 收藏
分享
求面试求offer啊啊啊啊:要求太多的没必要理
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务