#include <stdio.h> #include <stdlib.h> #include <math.h> int main() { unsigned long long k[4]; for(int i=0;i<4;i++){ scanf("%llu",&k[i]); } printf("\n"); printf("%.4f\n",sqrt(k[3])); printf("%.4f\n",sqrt(k[2])); printf("%.4f\n",sqrt(k[1])); printf("%.4f\n",sqrt(k[0])); return 0; } Ошибка на тесте 2 /Error in test 2 Edited by author 09.09.2018 15:45 Во входном потоке может быть любое количество чисел, а не только четыре. I tried hard and hard but was getting runtime error: access violation again and again because of not taking proper size of array. at last I used a[128*1024] by a solution of a discussion. and it worked. but how it was done? I mean I didn't get the clue line of question " A size of the input stream does not exceed 256 KB. " can you help me? 256KB of chars - like "1.2 11 1". Here are 3 numbers take 8 bytes. Size of minimal double representation is 2 bytes - "1 ". So 256K chars can be 128K doubles. I use type[256*1024] int main(){ ... } run successfully . but use struct as int main() { type[256*1024] } get error : access violation and use type[256*1024 / sizeof(type)] get error : access violation what is the "A size of the input stream does not exceed 256 KB." means! #include<stdio.h> #include<math.h> int main(){
float i=0,racuad[61]; int a=1,b=1;
while(i<=pow(10,18)){ racuad[a]=sqrt(i); a++; i=1+i*7843; } for(b=a-2;b>=0;b--){ printf("%.4f\n",racuad[b+1]); }
return 0; } #include <stdio.h> #include <math.h> void recur(void); int main() {
recur(); return 0; } void recur() { long int num; scanf("%ld", &num); if (num != EOF) recur(); printf("%.5f\n", sqrt(num)); } Edited by author 09.08.2018 18:20 package timusreverseroot; import java.text.DecimalFormat; import java.util.*; public class TimusReverseRoot { public static void main(String[] args) { DecimalFormat f = new DecimalFormat("#0.0000"); Scanner keyboard = new Scanner(System.in); String inputs = keyboard.nextLine(); String[] parsed = inputs.split(" ");
for (String parsed1 : parsed) { int square = (int) Math.pow(Integer.parseInt(parsed1), 2); System.out.println(f.format(square)); } }
} I added in the package line but if I left that in, it would give me a compilation error, why is that? And this code runs perfectly fine in Netbeans but the judge gives a compilation error Edited by author 07.05.2018 22:48 Edited by author 07.05.2018 22:49 Edited by author 07.06.2018 01:49 И в чем проблема напиши Как определить конец файла? file.eof(); Это точно C++? По моему это или ява или C#... Вот я тоже очень удивляюсь, как решать? Как я определю конец исходных данных? Попробовал залить бесконечный цикл, по времени не проходит... import java.io.InputStreamReader; import java.text.DecimalFormat; import java.util.Scanner; public class Reverse { private static void printer(double value){ String pattern = "###0.0000"; DecimalFormat myFormatter = new DecimalFormat(pattern); String output = myFormatter.format(value); System.out.println(output); } public static void main(String[] args) { Scanner sc = new Scanner(new InputStreamReader(System.in)); long a,b,c,d; a = sc.nextLong(); b = sc.nextLong(); c = sc.nextLong(); d = sc.nextLong(); printer(Math.sqrt(d)); printer(Math.sqrt(c)); printer(Math.sqrt(b)); printer(Math.sqrt(a)); } } In your solution, it is possible just 4 numbers (a,b,c,d). Suggestion: try using a loop instead of a,b,c,d and finish the loop when the user type something different than a number https://ideone.com/Ocpa4V I can't figure out what's wrong with my code. I used 'Queue' data structure. Edited by author 23.01.2018 16:02 #include<stdio.h> #include<math.h> #define size 256*1024/sizeof(long long) int main() { int s=0,l; long long int a[size+1]; do{l=scanf("%lld",a[s++]);}while(l!=EOF); for(s=s-2;s>=0;s--) printf("%.4Lf\n", sqrt((double)a[s])); } The input may contain upto 256 * 1024 / 2 numbers ("1 1 1 1 1 ..."). "отделённых друг от друга ПРОИЗВОЛЬНЫМ КОЛ-ВОМ пробелов и переводов строк" - это меня "убивает"... По сути ведь получается, что непонятно, когда заканчивается ввод исходных данных. Не так ли? Или я могу чего-то не знать? <python> есть такое понятие как константа EOF, она, собственно, и должна служить концом ввода Edited by author 10.01.2018 03:49 Edited by author 10.01.2018 03:49 #include "stdafx.h" #include<stdio.h> #include<math.h> int _tmain(int argc, _TCHAR* argv[]) { float a; scanf_s("%f", &a); printf_s("%6.4f", sqrt(a)); scanf_s("%f", &a); return 0; } #include<stdio.h> #include<math.h> #define n 4 int main(){ int a[n]={100000000}; int i; for(i=0; i<n; i++) scanf("%d", &a[i]); for(i=n; i>0; i--){ printf("%.4f\n", sqrt(a[i]));} return 0; } #include<stdio.h> #include<math.h> #define n 4 int main(){ int a[n]={100000000}; int i; for(i=0; i<n; i++) scanf("%d", &a[i]); for(i=0; i<n; i++){ printf("%.4f\n", sqrt(a[i]));} return 0; } import java.util.Scanner; import java.util.Stack; public class ReverseRoot_SplitDecimal {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in); Stack<Integer> integerNumberStack = new Stack<Integer>(); Stack<Short> floatingNumberStack = new Stack<Short>();
Double tempDouble = new Double(0);
while(sc.hasNextInt()) { tempDouble = Math.sqrt(sc.nextDouble()); integerNumberStack.push(Integer.parseInt(String.format("%.4f", tempDouble).split("\\.")[0])); floatingNumberStack.push(Short.parseShort(String.format("%.4f", tempDouble).split("\\.")[1])); }
while(!integerNumberStack.isEmpty()) { System.out.printf("\n%d.%04d", integerNumberStack.pop(), floatingNumberStack.pop()); } System.out.println();
sc.close(); } } Can anyone explain why this is saying wrong answer? namespace Ex2 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries); for (int a = input.Length - 1; a >= 0; a--) { double temp = Math.Sqrt(double.Parse(input[a])); if (temp == 0) { string zero = temp.ToString(); zero += ","; Console.WriteLine(zero.PadRight(6,'0')); } else { Console.WriteLine(temp); } } //Console.ReadLine(); } } } How many input lines are declared in the task? How many input lines in the example? How many lines your program expects? import java.util.Scanner; public class main { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(System.in); String a = scan.nextLine(); double b = Double.parseDouble(a); double c; double d = b; double mass[] = new double[(int)b]; while (b != 0) { c = Math.sqrt(scan.nextDouble()); mass[(int)(b - 1)] = c; b--; } for (double i = 0; i < d; i++) { System.out.printf("%.4f\n", mass[(int)i]); } } } Outputs "Runtime error" Edited by author 09.10.2017 00:50 Please look at example, try to find count of inputs you are reading into b. #include<stdio.h> #include<math.h> #include<stdlib.h> #define SIZE 128*1024 int main() { int i,n=0; long long int num[SIZE],N; printf("enter your aray value:\n"); while(scanf("%lld",&N)!=EOF) { num[n]=N; n++; } for(i=n-1;i>=0;i--){
printf("%0.4lf\n",(double)sqrt(num[i])); } return 0; } ohhh...thanks for your great suggestion. from re import * from math import sqrt result = findall('[0-9]+', input()) result.reverse() for i in result: print('{:.4f}'.format(sqrt(int(i)))) Edited by author 14.03.2017 01:20 For the most tasks WA1 means your program can't even solve sample. Have you tried to run it locally? It's clearly visible it doesn't work. Here's my run: http://ideone.com/T9g8rU There is only 2 numbers in output so your program processed first input line only. Edited by author 17.03.2017 14:35Hey admins! His code works well as my, but it doesn't pass on your side. As the prove look bellow: " with open('/tmp/123.txt', 'r') as f: string = f.read()
from re import * from math import sqrt result = findall('[0-9]+', string) result.reverse() for i in result: print('{:.4f}'.format(sqrt(int(i)))) " Answer " runfile('/home/ant/.config/spyder-py3/temp.py', wdir='/home/ant/.config/spyder-py3') 2297.0716 936297014.1164 0.0000 37.7757 " You have mistakes in comparation analysis on your side. Hi, master8282 please, take a look at rules: В решениях задач запрещается: работа с любыми файлами; ... (Source: http://acm.timus.ru/help.aspx?topic=judge) here is the problem, since your code based on file reading. import java.util.Scanner; public class JavaApplication12 {
public static void main(String[] args) {
double x,k; int a; double y =Math.pow(10,18);
System.out.println("Сколько хотите ввести чисел ? "); Scanner sc = new Scanner(System.in); a = sc.nextInt(); int arr[] = new int[a]; for(int j=0;j<a;j++) { do { arr[j] =(int) sc.nextLong(); } while (arr[j]<0 || arr[j]>y);
} for(int i=a-1;i>=0;i--) { k = Math.sqrt(arr[i]); System.out.println(k); }
} } >Сколько хотите ввести чисел? ))))) |
|