Make sure your code can choose devices other than the 1st one from the list... If you get WA22, problem in saving minimal price of devices. If there are several popular devices, you need to display the one with the cheapest price Try test: a htc 10000 b nexus 10000 c htc 99999 d nexus 10000 e htc 5000 f nexus 10000 answer is htc (the most minimal price is 5000) My code: #include<iostream> #include<map> #include<string> using namespace std; #define DL 0 //Debug log string SIB; //String input bufer unsigned long CIB; //Cost input bufer map<string, unsigned long>DC; //Devices cost map<string, unsigned long>DR; //Devices repits unsigned short RR; //Repits record unsigned long RC; //Record cost string O; //Output int main() { for (unsigned short i = 0; i < 6; i++) { cin >> SIB; cin >> SIB; cin >> CIB; if (CIB > RC) RC = CIB; if(DC[SIB] == 0 || DC[SIB] > CIB) DC[SIB] = CIB; DR[SIB]++; if (DR[SIB] > RR) RR = DR[SIB]; } if (DL) { cout << endl; cout << "Name repits cost:" << endl; for (auto i : DR) { cout << i.first << " " << i.second << " " << DC[i.first] << endl; } cout << endl; } for (auto i : DR) { if (i.second == RR) { if (DC[i.first] < RC) { RC = DC[i.first]; O = i.first; } } } cout << O; } Give me plz some test Edited by author 30.11.2019 17:00 tovars,prices,recomendations= [],[],[] for i in range(6): name = input() tovar = input() price = int(input()) if tovar in tovars: if prices[tovars.index(tovar)] > price: prices[tovars.index(tovar)] = price recomendations[tovars.index(tovar)] +=1 else: tovars.append(tovar) prices.append(price) recomendations.append(1) if recomendations.count(max(recomendations)) == 1: print(tovars[recomendations.index(max(recomendations))]) else: ans = [] ans1 = [] l = len(tovars) mm = max(recomendations) for i in range(l): if recomendations[i] == mm: ans.append(tovars[i]) ans1.append(prices[i]) print(ans[ans1.index(min(ans1))]) Can somebody give me this test ?! Please ! I guess all devices are unique. I've passed test 10 when i've passed this:
q a 1 q b 2 q c 3 q d 4 q e 5 q f 6 so what's the output for that test ??? If you're getting WA #10, better try this test where prices aren't already sorted: a 1 6 b 2 4 c 3 5 d 4 3 e 5 1 f 6 2 Correct answer is "5", got AC after this test passed. Don't forget about saving MIN PRICE of device Edited by author 31.03.2017 17:39 #include<stdio.h.> #include<string.h> int main() { int i,j,temp,re,q; int a[6]={0,0,0,0,0,0}; int b[6]; char c[6][20]; for(i=0;i<6;i++) { char d[20]; scanf("%s",d); scanf("%s",c[i]); scanf("%d",&b[i]); } for(i=0;i<6;i++) { for(j=0;j<6;j++) { if(strcmp(c[j],c[i])==0) a[i]++; } }
temp=a[0]; re=b[0]; for(i=0;i<6;i++) { if((a[i]>temp)||((a[i]==temp)&&b[i]<=re)) { temp=a[i]; re=b[i]; q=i; } }
printf("%s",c[q]); fflush(stdin); getchar(); return 0; }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Soap; using System.IO; namespace _2033 { class Device { public string Friend { get; set; } public string Name { get; set; } public int Cost { get; set; } } class Program { static void Main() {
List<Device> objList = new List<Device>(); for (int i = 0; i < 6; i++) objList.Add(new Device { Friend = Console.ReadLine(), Name = Console.ReadLine(), Cost = int.Parse(Console.ReadLine()) });
// 1. Находим девайс, который находится у большинства парней var query = from list in objList group list by list.Name into grouping orderby grouping.Count () descending where grouping.Count()>=2 select new {grouping.Key,PRCNT= grouping.Count ()} ; string Device = ""; int prev_cnt = 0; bool isFind = true; foreach (var item in query) { if (prev_cnt != 0 && item.PRCNT == prev_cnt) { isFind = false; break; } else if (prev_cnt >= 2 && item.PRCNT<prev_cnt) break; Device = item.Key; prev_cnt = item.PRCNT; } if (Device != "" && isFind) { Console.WriteLine(Device); return; }
//Если таких устройств несколько , то находим самое дешевое из них var query2 = objList.OrderBy(dev => dev.Cost); foreach (var item in query2) { Console.WriteLine(item.Name); return; } } } } just need examples. I have no idea where is my mistake import java.io.*; import java.util.*; //import java.math.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); //String[] name = new String[6]; String[] device = new String[6]; int[] price = new int[6]; Map<String,Integer> result = new TreeMap<String,Integer>(); Map<String,Integer> rprice = new TreeMap<String,Integer>();
for(int i=0; i<6; i++) { in.readLine(); device[i] = in.readLine(); price[i] = Integer.parseInt(in.readLine());
if(!result.containsKey(device[i])) { result.put(device[i],1); rprice.put(device[i],price[i]); } else { result.put(device[i],result.get(device[i])+1); if(price[i]<rprice.get(device[i])) rprice.put(device[i],price[i]); } } int rep = 1, max = 1; for(int i : new ArrayList<Integer>(result.values())) { if(max==i) rep++; if(max<i) { rep = 1; max = i; } }
if(rep==1) { for(String i : result.keySet()) if(max==result.get(i)) out.print(i); } else { int min=0; for(String i : rprice.keySet()) { if(max==result.get(i)) { if(min==0) min=rprice.get(i); else if(min>=rprice.get(i)) min=rprice.get(i); } } for(String i : rprice.keySet()) { if(min==rprice.get(i)) out.print(i); } } out.flush(); } } What's wrong? Here is my solution: var i,j,k,y,fl,s,t,max,min,r:longint; a:array [1..100] of string; b,c:array [1..100] of longint; d,x:string; begin for i:=1 to 6 do begin readln (d); readln (x); readln (y); fl:=0; for j:=1 to k do If a[j]=x then fl:=j; If fl=0 then begin k:=k+1; a[k]:=x; b[k]:=y; c[k]:=1;end; If fl>0 then If y<b[fl] then begin b[fl]:=y; c[fl]:=c[fl]+1;end else c[fl]:=c[fl]+1; end; max:=-2000000000; for i:=1 to k do if c[i]>max then max:=c[i]; for i:=1 to k do if c[i]=max then begin s:=s+1; r:=i;end; If s=1 then writeln (a[r]) else begin min:=2000000000; for i:=1 to k do If b[i]<min then min:=b[i]; i:=0; repeat i:=i+1; if b[i]=min then writeln (a[i]); until (b[i]=min) or (i=k); end; end. |
|