Show all threads Hide all threads Show all messages Hide all messages |
Why Runtime error | Vlad | 1001. Reverse Root | 12 Aug 2019 10:16 | 2 |
import java.util.Scanner; public class Main { private static void checking(double a){ if(Math.sqrt(a)%1==0){ System.out.printf("%.0f",Math.sqrt(a)); }else{ System.out.printf("%.4f",Math.sqrt(a)); } } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Сколько чисел хотите ввести: "); int a = scanner.nextInt(); double[] b = new double[a]; for (int i = 0; i < b.length; i++) { System.out.print("Число " + (i+1) + ": "); b[i] = scanner.nextDouble(); } for(double c : b){ System.out.print("Корень " + c + " = "); checking(c); System.out.println(); } } } I'm not sure what's causing the runtime error, but I tried your code on an online compiler and this was the error message I got: Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextDouble(Scanner.java:2564) at Main.main(Main.java:22) |
[PYTHON] Can anyone please tell me why this gives wrong answer on test 1? It works fine with my compiler fo a lot of cases. | rayneh | 1001. Reverse Root | 12 Aug 2019 10:01 | 2 |
import math import re input_string = '' while True: line = input() if line: input_string = input_string + ' ' + line else: break input_digits = [int(x) for x in input_string.replace('\n',' ').replace('\t', ' ').split()] input_digits = input_digits[::-1] for int in input_digits: sqr_root = math.sqrt(int) print(format(sqr_root, '.4f')) #Thanks for the help guys! I tested your code on some online compilers, and the last two answers were printed, but not the first two. It looks like your algorithm correctly read the first line, but because there were empty lines for the next couple lines, your break statement kept the code from reading the last two lines in the example testcase. You need to change the code so it can read all the lines, even the ones that come after empty lines. |
Подскажите в чем трабл? | Sprint_me | 1001. Reverse Root | 21 Jul 2019 11:06 | 2 |
import sys from math import sqrt potok = sys.stdin.read() spisok = potok.split()[::-1] if sys.getsizeof(potok)>262144: print('большой объем') quit() for i in spisok: i=int(i) if i>10**18 or i<0: print('неверный диапозон') quit() res = sqrt(int(i)) print("%.4f" % res) del Edited by author 21.07.2019 11:08 |
1001. Reverse Root | Suraj Sharma | 1001. Reverse Root | 20 Jun 2019 11:03 | 1 |
The following code is failing the test case 3, I have used linked-list to store the data in as a stack. Below is the code for reference, can you tell me where I am going wrong. Thank you. #include<stdio.h> #include<stdlib.h> #include<stdbool.h> #include<math.h> #include<assert.h> typedef unsigned long long _ull; typedef unsigned int _uint; typedef struct _link_list { _ull _number; struct _link_list*_next; } _list; void _makenode(_list**,_ull); void _insertnode(_list**,_list*); int main(int argc,const char*argv[]) { _ull _val; _list *_head,*_temp; _head = _temp = NULL; while(true) { fscanf(stdin,"%lld",&_val); assert(_val>=0); if(feof(stdin)) break; _makenode(&_head,_val); } while(_head) { _temp = _head; fprintf(stdout,"%0.4lf\n",sqrt(_head->_number)); _head = (_head->_next); free(_temp); } return 0; } void _makenode(_list**_ptr,_ull _data) { _list*_node = malloc(sizeof(_list)); (_node->_number) = _data; (_node->_next) = NULL; _insertnode(_ptr,_node); } void _insertnode(_list**_ptr,_list*_node) { if(!(*_ptr)) (*_ptr) = _node; else { (_node->_next) = (*_ptr); (*_ptr) = _node; } } |
why wrong answer(3)? c++ | Dima Puz | 1001. Reverse Root | 17 Apr 2019 08:09 | 3 |
[code deleted] Edited by author 02.04.2019 21:28 Edited by author 02.04.2019 21:49 Edited by moderator 19.11.2019 23:34 Change while (!cin.eof()){ cin >> a; mass.push_back(a); } mass.erase(mass.end()-1); To while (cin >> a) { mass.push_back(a); } |
C: Whats wrong with task? | Nick | 1001. Reverse Root | 22 Mar 2019 07:43 | 2 |
I've created file with tests, it seems all checks passes locally, but not in Judge here is my code: #include <stdio.h> #include <stdlib.h> #include <math.h> typedef struct list_node{ long int number; struct list_node * previous; } list_node_t; list_node_t * create_root(long int number); list_node_t * create_list(long int number, list_node_t * previous); int main() { long int a; list_node_t * current = NULL; while (scanf("%ld", &a) != EOF) { if (current == NULL) { current = create_root(a); } else { current = create_list(a, current); } } while (current != NULL) { printf("%.4Lf\n\r", sqrtl(current->number)); current = current->previous; } return 0; } list_node_t * create_root(long int number) { list_node_t *lt = malloc(sizeof(list_node_t)); lt->number = number; lt->previous = NULL; return lt; } list_node_t * create_list(long int number, list_node_t * previous) { list_node_t *lt = create_root(number); lt->previous = previous; return lt; } the problem is just calculate the square root in reverse order, it is unnecesary create a linked list or use pointer |
что не так с кодом? | Demorald | 1001. Reverse Root | 17 Mar 2019 04:01 | 1 |
#include <iostream>; #include <vector>; #include <string>; #include <sstream>; #include <iomanip> using namespace std; int main() { int temp; vector <double> answers; string s; getline(cin, s); istringstream iss(s); while (iss >> temp) { double a = sqrt(temp); answers.push_back(a); } for (int i = answers.size(); i > 0; i--) { cout << fixed << setprecision(4) << answers[i-1]; cout << endl; }
system("pause"); return 0; } |
why wrong answer? Pascal version | pizza_hunter | 1001. Reverse Root | 10 Mar 2019 13:20 | 1 |
This is my code ----------------------------------------- var j,i: longint; a: array[1..100000000] of real; begin i:=1; while not EOF do begin read(a[i]); i:=i+1; end; for j:=i-1 downto 1 do writeln(sqrt(a[j]):0:4); end. ----------------------------------------- Why is it wrong? can anyone please explain? thanks a lot Edited by author 10.03.2019 13:21 |
why show me wrong answer for this problem of 1001?? My compiler give me a right answer.. | Amit_guha | 1001. Reverse Root | 10 Mar 2019 13:16 | 3 |
#include<bits/stdc++.h> #include<math.h> using namespace std; int main() { long long int i,j,k,s; double a,b,c,d; scanf("%lld %lld %lld %lld",&i,&j,&k,&s); if(s>=0) { d=sqrt(s); printf("%.4f\n",d); } if(k>=0) { c=sqrt(k); printf("%.4f\n",c); } if(j>=0) { b=sqrt(j); printf("%.4f\n",b); } if(i>=0) { a=sqrt(i); printf("%.4f\n",a); } return 0; } Why do you think there are only four numbers in input? Why do you think a number can be negative? If you are new to OJ system... The point is, the system will input any case that satisfies its question, not only the sample input. Therefore, there might not be only 4 numbers for you to consider. It may input 100 numbers, which your code obviously cannot give the correct output. |
It's interesting.. | FanThomas | 1001. Reverse Root | 5 Feb 2019 01:03 | 1 |
All compilers are succeed with this code. What's wrong? #include <iostream> #include <iomanip> #include <cmath> using namespace std; int main() { double buffer[128*1024]; unsigned long long number, n=0; while(cin >> number) { buffer[n]=pow(number,1.0/2.0); n++; } for (int i=n-1;i>=0;i--) { cout << fixed << setprecision(4) << buffer[i] << endl; } return 0; } |
Why Runtime error | Izazul Haque Saad | 1001. Reverse Root | 17 Jan 2019 01:46 | 1 |
#include<stdio.h> #include<stdlib.h> #define x 100000 int main() { long long int n , c=0,i; double ar[x] = {}; while(scanf("%lld",&n)){ if(n < 0) break; ar[c++] = n; } for(i=c-1; 0<=i; i--){ printf("%.4lf\n",sqrt(ar[i])); } return 0; } |
Почему при проверке выбрасывает "Wrong answer"? | Ilya | 1001. Reverse Root | 30 Nov 2018 13:56 | 2 |
#include <iostream> #include <math.h> #include <iomanip> using namespace std; int main(int argc, char const *argv[]) { long number; double sqrts[256]; int k = 0; while ( cin >> number ) { sqrts[k] = sqrt(number); k++; } for ( int n = k - 1; n > -1; n-- ) { cout << fixed << setprecision(4) << sqrts[n] << endl; } return 0; } Edited by author 29.11.2018 20:32 http://acm.timus.ru/help.aspx?topic=cpp C and C++ programs are compiled on the server with the 32-bit Microsoft Visual C++ 2017 or MinGW GCC 7.1 or Clang 4.0.1. So sizeof(long)==4. You should run locally/debug programs using 32 bit compiler too. Btw, why do you think 256 sqrts is enough? How did you estimate it? |
WA на первом тесте pascalABC. Что не так ? *HELP* | Kety Pirozhkova | 1001. Reverse Root | 28 Nov 2018 21:20 | 1 |
скорее всего ошибка с функцией Eof() ибо впервые ей пользуюсь и смутно представлю принцип работы. Если её нельзя использовать, то как найти конец вводимого файла? var s,sk:string; var i,fl,j,code:integer; var n:real; var a:array [1 ..256] of real; var f:array [1 ..256] of integer; begin while (Eof()<>True ) do begin readln(s); for i:=1 to length(s) do begin if (s[i]<>' ') and (fl=0) then begin fl:=1; sk:=sk+s[i]; end else if (s[i]<>' ') and (fl=1) then sk:=sk+s[i];
if (((s[i]=' ') and (fl=1)))or ((i=length(s))and(fl=1)) then begin fl:=0; val(sk,n,code); for j:=1 to 256 do if f[j]<>1 then begin a[j]:=sqrt(n); f[j]:=1; sk:=''; n:=0; break; end;
end; end;end; for i:=1 to 256 do if (f[i]=1) then writeln(a[i]:0:4); end. |
I don't know why wrong answer ? Can you help me ? please! | QUANGPHAM | 1001. Reverse Root | 23 Nov 2018 13:39 | 2 |
#include <iostream> #include <iomanip> #include <math.h> using namespace std; int main(){ unsigned long long input; double array[4]; int dem = 0; while (dem < 4 && cin >> input ){ array[dem] = sqrt(input); dem++; } for ( int i = dem - 1; i >= 0; i--) cout << setprecision(4) << fixed << array[i] << endl; } there should not have a array that with 4 length, it may have 5 or 6 or 100...echo, there is no limit |
хммм, что не то? what??? | dainil | 1001. Reverse Root | 10 Nov 2018 00:35 | 1 |
import math a=input().split() for i in range(len(a)): u=int(a[i]) l=str(math.sqrt(u))+'0000' for x in range(len(l)): if l[x]=='.': print(l[0:x+5]) Edited by author 10.11.2018 00:35 |
Python Wrong answer. Первый раз на этом сайте. Что не правильно? | Altynbek | 1001. Reverse Root | 9 Nov 2018 15:00 | 2 |
intxt = input() for i in intxt.split()[::-1]: print('%.4f' % int(i) ** 0.5) IIRC, Python's input() reads only one line. You should probably do this for every line in sys.stdin. Well, rarely do I write solutions in Python so I might be wrong. |
Why Runtime error (Stack Overflow)??? | Iqramul Islam | 1001. Reverse Root | 31 Oct 2018 17:01 | 5 |
#include <iostream> #include <math.h> using namespace std; void square() { long long int n; scanf("%lld", &n); if(n!=-1) { square(); printf("%.4f\n", sqrt(n)); } return; } int main() { square(); return 0; } http://acm.timus.ru/help.aspx?topic=cpp&locale=en Visual C++ Only. In order to increase the size of a stack and to avoid its overflow when using a “deep” recursion, you should use a special directive (in the example, the size of the stack is set to be 16 MB): #pragma comment(linker, "/STACK:16777216") sorry i don't understand .. how to set the size of the stack??? If you can explain... it might help me..... #pragma comment(linker, "/STACK:16777216") Put the line above in the very beginning of your program, that all. You shouldn't touch stack size at all. You shouldn't implement algorithms with linear depth of recursion, not more then logarithmic depth. You shouldn't place big arrays/objects on stack. Imagine you have 1-2K stack at all. You should get/implement stack data structure and solve problem using it. |
Why is that wrong on the first test | dukallis | 1001. Reverse Root | 23 Oct 2018 19:02 | 2 |
#include <iostream> #include <cmath>
void rSqrt(void) { unsigned long int n = 0; if (scanf("%lu", &n) != -1) ¦ rSqrt(); else ¦ return; printf("%.4f\n", sqrt(n)); return; }
int main() { rSqrt(); return 0; } C and C++ programs are compiled on the server with the 32-bit Microsoft Visual C++ 2017 or MinGW GCC 7.1 or Clang 4.0.1. So, sizeof(unsigned long)==4. Edited by author 23.10.2018 19:03 |
Как решать? | Aleksandr Starkov [IATE] | 1001. Reverse Root | 22 Oct 2018 19:53 | 2 |
На каких значениях становить ввод? Until the end of the string. You may use: while (scanf(...) != EOF); |
Python 3.6 What's wrong with the code? Что не так с кодом? | 2tlin | 1001. Reverse Root | 6 Oct 2018 21:56 | 2 |
L = [] string = input() while string: [L.append(int(num)**0.5) for num in string.rstrip().split(' ') if num != ''] string = input()
for i in L[::-1]: print('%.4f'%i) Edited by author 06.05.2018 03:54 Edited by author 06.05.2018 03:54 Edited by author 06.05.2018 03:54 Edited by author 06.05.2018 03:54 Поздно, наверное, но он же у тебя не считывает пустую строку. Из 4-х чисел теста номер 1, он обработал только первые два. |