Show all threads Hide all threads Show all messages Hide all messages |
WA 6, python 3.8, plz help me | klimvetoshkin | 1263. Elections | 28 Jan 2023 11:58 | 1 |
n, m = map(int, input().split()) a = [] b = [1] c = [] for i in range(m): f = int(input()) a.append(f) a = sorted(a) f = 0 for i in range(1, len(a)): if a[i] == a[i - 1]: b[f] += 1 elif a[i] != a[i - 1]: b.append(1) f += 1 for i in range(len(b)): b[i] = float(b[i] / m * 100) for i in range(len(b)): c.append('%.2f' % b[i] + '%') for i in range(n): try: print(c[i]) except: print('0.00%') |
I think everything is okay but i got WA.... | onevoltman | 1263. Elections | 2 Jan 2022 06:40 | 1 |
#include <stdio.h> int main () { int n, m; scanf("%d %d", &n, &m); int ara[n+1]{0}, temp; double result{0}; for (int i = 1; i <= m; i++) { scanf("%d", &temp); ara[temp]++; temp = 0; } for (int i = 1; i <= n; i++) { if(m == 0) { printf("0.00%\n"); continue; } result = (100.0 * ara[i] / m); printf("%2.2lf", result); printf("%\n"); } return 0; } |
What's wrong? test 3 WA | Alex | 1263. Elections | 13 Sep 2021 21:19 | 1 |
My code: n,m = map(int, input().split()) dct = dict() for i in range(m): a = input() if a not in dct: dct[a] = 1 else: dct[a] += 1 for i in dct: print("{0:.2f}%".format((dct[i]/m)*100)) Where is mistake? Edited by author 13.09.2021 21:32 |
WA12 | Rodion | 1263. Elections | 24 Jul 2021 22:30 | 1 |
WA12 Rodion 24 Jul 2021 22:30 |
WA on test #12 can someone help me ? | stilkobg | 1263. Elections | 24 Jul 2021 22:27 | 6 |
#include<iostream> #include<iomanip> #include<math.h> using namespace std; double a[10001]; int main() { int l=0,i,n,k; double x,m; cin>>n>>m; for(i=0;i<m;i++) { cin>>k; a[k]++; } for(i=1;i<=n;i++) { x=a[i]/m; x*=100; if(ceil(x)==floor(x))cout<<x<<".00%"<<endl; else cout<<setprecision(4)<<x<<'%'<<endl; } return 0; } Edited by author 09.04.2008 22:50 I have this Problem too. plz help, my program is been written in JAVA. Edited by author 13.10.2011 16:36 So, I have this problem too. What is the rigth solution? --- I found the answer, use Console.WriteLine("{0:f2}%", t); Edited by author 25.10.2012 19:37 Edited by author 25.10.2012 19:37 Try these inputs: 2 11 1 2 2 2 2 2 2 2 2 2 2 I change this >> first multiply 100 and then divide m . and it works. |
WA#1 correct answer for sample out test 1 | Bobojon Bobojonov | 1263. Elections | 19 Apr 2021 12:27 | 1 |
object Election1263 extends App { val Array(n, m) = scala.io.StdIn.readLine().split(" ").map(_.toInt) val list = (0 to m - 1).foldLeft(List.empty[Int]){case (acc, _) => scala.io.StdIn.readLine().split("\n").map(_.toInt).toList match { case head :: Nil => acc :+ head case _ => acc } } val electionList = list.groupBy(identity).foldLeft(List.empty[Int]) {(s, e) => s :+ e._2.size } def getPersent(list: List[Int], list1: List[Double]) : List[Double] = list match { case head :: tail => getPersent(tail, list1 :+ head * 100.0 / m) case head :: Nil => getPersent(Nil, list1 :+ head * 100.0 / m) case _ => list1 } val result = getPersent(electionList, List()) result.foreach(e => println("%.2f".format(e) + "%") ) } |
Java Ans. | koti4 | 1263. Elections | 24 Feb 2021 14:26 | 1 |
import java.util.*; public class j { public static void main(String[] args){ Scanner input = new Scanner(System.in); int bin,sum = 0; int n=input.nextInt(); int m=input.nextInt(); int [] mas = new int [n]; for(int i = 0;i<m;i++){ bin = input.nextInt(); sum += 1; mas[bin-1] = mas[bin-1] + 1; } for(int i = 0;i<n;i++){ System.out.println(String.format("%.2f",mas[i]/(sum*0.01))+"%"); } } } |
WA task1263 | AlexStrong | 1263. Elections | 9 Jul 2020 23:16 | 1 |
I don’t understand what is the mistake here. Help pls string[] val = Console.ReadLine().Split(' '); double[] k = new double[10000]; for(int i = 0; i < Convert.ToInt32(val[1]); i++) { string s = Console.ReadLine(); k[Convert.ToInt32(s) - 1]++; } double swap = 0; for(int i = 0; i < k.Length-1; i++) { for(int j = i + 1; j < k.Length - i - 1; j++) { if (k[j+1] > k[j]) { swap = k[j+1]; k[j+1] = k[j]; k[j] = swap; } } } for (int i = 0; i < Convert.ToInt32(val[0]); i++) {
Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0:N2}", (100 * k[i]) / Convert.ToDouble(val[1]))+"%"); }
|
Why RuntimeError on Test 6 Java | DWinter | 1263. Elections | 6 Mar 2020 12:36 | 3 |
import java.io.PrintWriter; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.Scanner; public class Task_1263 { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); String str = in.nextLine(); int candidateCount = Integer.valueOf(str.substring(0, 1)); int votersCount = Integer.valueOf(str.substring(2)); int[] votersForCandidates = new int[candidateCount]; double[] votersPercents = new double[candidateCount]; int voter; for (int i = 0; i < votersCount; i++) { voter = Integer.valueOf(in.nextLine()); votersForCandidates[voter - 1]++; } for (int i = 0; i < candidateCount; i++) { votersPercents[i] = new BigDecimal((double) 100 * votersForCandidates[i] / votersCount).setScale(2, RoundingMode.HALF_UP).doubleValue(); } for (int i = 0; i < candidateCount; i++) { out.printf("%.2f%%%n", votersPercents[i]); } out.flush(); } } Because of the Memory limit: which no more than 64 MB. votersPercents array is useless and should be removed. But the main error is you reading candidateCount in the wrong way. str.substring(0, 1) - how many digits can you read? What max candidateCount is? You use Scanner class. It has method nextInt() - you can just use it, you don't need to read strings and split them into numbers manually. |
WA test 3??!! | Ralph | 1263. Elections | 27 Feb 2020 20:30 | 4 |
Could anybody give me some tricky tests? This problem seems to be trivial but I got WA. I guess it's all about format of result. Thank you! We should pay attention to the case when there is any candidates that no one votes for him or her Thanks! Most helpful answer here! |
Why Wrong Answer №6? | despair_101 | 1263. Elections | 28 Dec 2019 21:59 | 1 |
using System; namespace Training { class Program { static void Main(string[] args) { string[] n = Console.ReadLine().Split(' '); int N = Convert.ToInt32(n[0]); int M = Convert.ToInt32(n[1]); double cnt = 1; int arr = 0; int[] ans = new int[M]; double[] vs = new double[N]; for (int i = 0; i < M; i++) ans[i] = Convert.ToInt32(Console.ReadLine()); Array.Sort(ans); Array.Resize(ref ans, ans.Length+1); Console.WriteLine(); for (int j = 0; j < M; j++) { if (ans[j] == ans[j + 1]) cnt++; else { double x = Math.Round(cnt / M * 100, 2); if ((int)x == x) Console.WriteLine(x + ".00%"); else Console.WriteLine(x + "%"); arr++; cnt = 1; } } if (arr < N) for (int j = 0; j < N - arr; j++) Console.WriteLine("0.00%"); } } } |
Find Mistake ( If You Can !!! :D ) | Thunderbolt | 1263. Elections | 3 Nov 2019 16:47 | 4 |
int main() { int n , m; cin >> n >> m; int *counter = new int [n]; for ( int i = 0 ; i < m ; i++ ) { int temp; cin >> temp; counter[temp-1]++; } for ( int i = 0 ; i < n ; i++ ) { float result = (float)counter[i] * (float)100 / (float)m; printf ("%.2f%%\n" , result); } delete[] counter; return 0; } (WA On Test 1) printf() also does the same work as cout<< I think the problem is from using int*counter.. Try using vector<int>counter(n); instead.. It worked fine when i tested it with the rest of your code |
Завалено на 2 тесте! Язык питон 3 | Gosha | 1263. Elections | 13 Oct 2019 21:11 | 3 |
m = [] g = [] d, b = map(int, input().split(' ')) for i in range(1, b+1): n = int(input()) m.append(n) for i in range(1, d+1): g.append(i) for i in range(d): f = 0 for y in range(b): if m[y] == g[i]: f += 1/b*100 f = round(f, 2) a = str(f) if len(a) == 4: print(a+'0%') else: print(a+'%') при 100% проголосовавших выводится 100.0%. Edited by author 30.12.2018 18:16 Попробуй вариант где ответ - 100% |
Python 3, wrong on test 2 | Krasheninnikova | 1263. Elections | 16 Aug 2019 21:55 | 2 |
n, m = map(int,input().split(' ')) voices = [] p = ['p'] h = 0 for i in range(m): voices.append(int(input()))
for i in range(n): p.append(0) for i in voices: for c in range(n+1): if i == c: p[c] += 1
for i in range(1, len(p)): h = p[i] / m * 100 p[i] = str(round(h, 2)) if len(p[i]) == 4: p[i] += '0' print(p[i] + '%') Help. what's wrong n, m = map(int,input().split(' ')) voices = [] p = ['p'] h = 0 for i in range(m): voices.append(int(input())) for i in range(n): p.append(0) for i in voices: for c in range(n+1): if i == c: p[c] += 1 for i in range(1, len(p)): h = p[i] / m * 100 print(f'{h:.2f}%') This is your code that prints the right answer. Python 3 uses BANKER'S rounding while the problem asks you to the MATHEMATICAL rounding. I used 'f-string' to perform MATHEMATICAL rounding. Anyways, the solution is not fast enough - try to come up with some speed-ups. |
WA test №6 Python | Alex | 1263. Elections | 14 Jul 2019 02:59 | 2 |
import math nm = input().split() n = int(nm[0]) m = int(nm[1]) res = set() result = [] for i in range(m): x = int(input()) if x not in res: res.add(x) result.append(x) answer = [] for i in res: answer.append(result.count(i)) while n - len(answer) > 0: answer.append(0) for i in answer: v = str(round(i*100/m, 2)) if v[-2] + v[-1] == '.0': print(str(round(i*100/m, 2)) + '0%') else: print(str(round(i*100/m, 2)) + '%')
Edited by author 24.02.2019 01:39 Edited by author 09.03.2019 03:19 n, m = [int(x) for x in input().split()] x = 0 k = [0]*(n) for i in range(m): x = int(input()) k[x-1] = k[x-1]+1 for u in range(n): print( "%.2f" % (k[u]*100/ m), "%", sep="" ) |
Restricted function.Python | Ilya_python | 1263. Elections | 3 Aug 2018 00:39 | 1 |
import numpy n,m=input().split() a=[] for i in range(int(m)): a.append(int(input())) b=numpy.zeros(int(n)) for i in range(int(n)): b[i]=a.count(i+1)/int(m)*100 print('%.2f' % b[i]+'%') Answer from system:Restricted function |
WA#12 | victoria_votokina | 1263. Elections | 22 May 2018 18:12 | 1 |
WA#12 victoria_votokina 22 May 2018 18:12 Help! What's wrong with my code? #include <bits/stdc++.h> #define forn( i, n ) for( int i = 0; i < n; i ++ ) using namespace std; int main() { int qq[10000]; int k, l; double m , n; l = 0; cin >> k >> n; forn( i , n) cin >> qq[i]; forn( i, k+1 ){ forn( j , n) if (qq[j] == i) l = l+1; if ( i != 0 ) { m = (l / n * 100); l = (int) round(m*100)/100; if ( l - m == 0) cout << round(m*100)/100 << ".00%" << endl; else cout << round(m*100)/100 << "%" << endl; l = 0; } } return 0; } |
I have some mistakes, help me find it!!! | Sergey Volodin | 1263. Elections | 7 Jan 2018 17:36 | 1 |
a=input().split() t=0 for i in range(len(a)): c=a[t] v=int(c) a[t]=v t=t+1 e=[0] s=[0] z=[0] q=[0] y=1 for i in range(a[1]): d=int(input()) s.append(d) s.remove(s[0]) for i in range(0,a[0]): w=s.count(y) z.append(w) w=0 y=y+1 z.remove(z[0]) t=0 for i in range(len(z)): c=z[t] v=int(c) z[t]=v t=t+1 t=0 c=0 for i in range(len(z)): c=z[t]/a[1] c=c*100 q.append(c) t=t+1 q.remove(q[0]) t=0 c=0 for i in range (len(q)): c=round(q[t],2) e.append(c) t=t+1 e.remove(e[0]) t=0 for i in range (len(e)): print(e[t],"%") t=t+1 |
Timing results | Megakrit | 1263. Elections | 9 Dec 2016 02:10 | 3 |
Hi, folks! Can anyone give me the source code in C# of this task (mine is already AC) when the timing is less than 0.1 sec? Or can anyone give me the key notes how it can be decreased in almost ten times? Thanks in advance! I presume your sol is O(NM), right? Think a bit. There is O(N+M) solution which definitely has time better than 0.1 sec. 1) Be sure that your algorithm is O(N+M) 2) When calculating percents you should not do: value * 100 / number inside cycle, it is better to calculate "100.0 / number" one time before cycle and then just perfom multiplying. 3) I used float for keeping values, not int. I think it saves time of casting from int to float. When I used 2 and 3 my time for c# decreased from 0.109 to 0.046. |
WA in test #2 C++ | LasTAD | 1263. Elections | 9 Dec 2016 01:31 | 2 |
#include <iostream> using namespace std; int main() { int cand, ch; cin >> cand >> ch; int* Ch = new int[ch]; double* Cand = new double[cand]; for (int i = 0; i < cand; i++) { Cand[i] = 0; } for (int i = 0; i < ch; i++) cin >> Ch[i]; for (int i = 0; i < ch; i++) { Cand[Ch[i]-1] += 1; } for (int i = 0; i < cand; i++) { printf("%.2f%%\n", (Cand[i]/6.0)*100.0); } } +++++++++++ Why this isn't work? What is the hardcoded value "6" in your code? |