|
|
Page 27 #include <iostream> using namespace std; int main() { double k; while(cin >> k) { cout << fixed << setprecision(4) << sqrt(k) << endl; } } I think the solution is supposed to start from the last number I want to solve the problem using a dynamic array. But the compiler outputs this: HEAP CORRUPTION DETECTED: after Normal block (#150) at 0x000001EEFBCDB420. CRT detected that the application wronte to memory after end of heap buffer. #include <iostream> #include <cmath> #include <iomanip> using namespace std; void main() { int size = 0, i = 0; int* a = new int[size]; unsigned int x; while (cin >> x) { size += 1; for (; i < size;++i) { a[i] = x;
} }
for (int i = size-1; i >= 0; --i) { cout << fixed << setprecision(4) << sqrt(a[i]) << endl; } delete[] a; Edited by author 20.03.2023 12:40 Type int will overflow. Use unsigned long long instead. When need stop the flow. Help me pls! Try use any symbol, i.e. "\" when need to stop using System; public class Reverse { private static void Main() { string[] numbers = Console.ReadLine().Split(new char[] {' ', '\t', '\n', '\r'}, StringSplitOptions.RemoveEmptyEntries);
for(int i = numbers.Length-1; i >= 0; i--) { double result = Math.Sqrt(double.Parse(numbers[i])); Console.WriteLine($"{result:F4}"); } } } Edited by author 07.03.2023 20:45 #include <cstdlib> #include <iomanip> #include <iostream> #include <cstdio> #include <math.h> #include <vector> #include <string.h> #include <algorithm> using namespace std; vector <double> numbers = {}; int main(int argc, const char * argv[]) { double n; while (std::cin >> n) { numbers.push_back(n); if (cin.peek() == '\n' ){ reverse(numbers.begin(),numbers.end()); for(int i = 0;i < numbers.size();++i){ cout<<fixed<<setprecision(4)<<sqrt(numbers[i])<<endl; } break; }; }
return 0; } I have a correct answer with input numbers in sample, and i see message "wrong answer" in 2 test. First test was passed, but i don't see where i lose... #include <iostream> #include <vector> #include <iomanip> #include <cmath> using namespace std; int main (){ double Input=0 ; double number[] ; int counter=0; while ( cin >> Input && Input != EOF){ number[counter] = Input; cout << number[counter]; counter++ ; } for (int i=counter ; i>0; i--){ cout << setprecision(4) << sqrt (number[counter]) << endl; } } a=[int(i) for i in input().split()] for i in a[::-1]: print(f"{float(i)**0.5:.4f}") because u proggram should take more one string. But i too not lnow how solve this task Edited by author 27.12.2022 14:22 #include<stdio.h> #include<math.h> int main(){ unsigned long long int a,b,c,d; double Sqrt,Sqrt1,Sqrt2,Sqrt3; scanf("%llu %llu %llu %llu",&a,&b,&c,&d); Sqrt=sqrt(a); Sqrt1=sqrt(b); Sqrt2=sqrt(c); Sqrt3=sqrt(d); printf(" %0.4lf %0.4lf %0.4lf %0.4lf",Sqrt,Sqrt1,Sqrt2,Sqrt3); } Edited by author 23.06.2022 13:46 Edited by author 23.06.2022 13:46 I'm just learning python. Can you please tell me where could be the error? import math data = input() length = len(data) list = [] i = 0 while i < length: if data[i] != " " and data[i] != "\n": end_index = i for j in range(i + 1, length): if data[j] == " " or data[i] == "\n": break end_index += 1 list.insert(0, int(data[i:end_index + 1])) i = end_index + 1 else: i += 1 for e in list: value = round(math.sqrt(e), 4) print(f'{value:.4f}') You only need to write about 3 lines of python code to solve this. try: help(str.split) help(reversed) help(str.join) package main import( "fmt" "strings" "bufio" "os" "strconv" "math" ) func main(){ scanner := bufio.NewScanner(os.Stdin) scanner.Scan() line := scanner.Text() s := strings.Fields(line)
for ix := len(s) - 1; ix >= 0; ix--{ i, _ := strconv.Atoi(s[ix]) x := fmt.Sprintf("%.4f", math.Sqrt(float64(i))) fmt.Println(x) } } #include <iostream> #include <stack> #include <cmath> using namespace std; int main() { stack<double> root; double input;
while(cin >> input) { root.push(sqrt(input)); }
while(!root.empty()) { cout << root.top() << endl; root.pop(); }
return 0; } Here your first input while is going infinnity. You have to stop it. import re pattern = re.compile(r"\d+") matches = re.findall(pattern, input()) for i in matches[::-1]: print(f"{float(i)**0.5:.4f}") Input: " 1427 0 \n 876652098643267843 \n5276538" Why is here the runtime error on the 6 test? What test is 6? #include <iostream> #include <cmath> using namespace std; void ghjkl(long double p) {cout << fixed; cout.precision(4); cout << p << endl;} int main() { long double a[1000]={-1.0}; long long i=0; while(cin) {cin >> a[i]; i++;} i=i-2; long double b[1000]; for(int k=0; k<1000; k++) {b[k]=sqrt(a[k]);} for(int m=i; m>=0; m--) {ghjkl(b[m]);} return 0; } Edited by author 24.03.2021 16:53 Edited by author 24.03.2021 16:54 i don't know Edited by author 31.03.2021 19:27 Edited by author 31.03.2021 19:27 Edited by author 31.03.2021 19:27 Oh, I have understood. The array isn't the needed collection for this task. Stack is better. #include <iostream> #include <stack> #include <cmath> using namespace std; int main() { stack<double> a; double b; int c=0; while(cin) {cin >> b; a.push(b); c++;} c-=1; a.pop(); for(int i=0; i<c; i++) {cout << fixed; cout.precision(4); cout << sqrt(a.top()) << endl; a.pop();} return 0; } Edited by author 10.06.2021 03:35 Or you can use deque: #include <iostream> #include <queue> #include <cmath> using namespace std; int main() { deque<double> a; double b; int c=0; while(cin) {cin >> b; a.push_back(b); c++;} c-=1; a.pop_back(); for(int i=0; i<c; i++) {cout << fixed; cout.precision(4); cout << sqrt(a.back()) << endl; a.pop_back();} return 0; } #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { long long val = 0; vector<double> v; while (cin >> val &&val!=EOF) { v.push_back(sqrt(val)); } for (int i = v.size()-1; i >=0; i--) { cout<< v[i] << endl; } return 0; } Set your val type to double for (int i = v.size()-1; i >=0; i--) { cout << fixed << setprecision(4) << v[i] << endl; } use this. your program is supposed to print 4 points for (int i = v.size()-1; i >=0; i--) { cout << ios::fixed << setprecision(4) << v[i] << endl; } try to change "long long val" to "double val" #include <iostream> #include <vector> #include <cmath> using namespace std; int main() { double val = 0; vector<double> v; char ch = 0; while (cin >> val) { v.push_back(val); } for (int i = 0; i < v.size(); i++) { cout << sqrt(v[i]) << endl; } } OK. Read this carefully: "For each number Ai from the LAST one till the FIRST one..." Second for loop cout from last element of the vector to first import java.util.Scanner; import java.math.RoundingMode; import java.text.DecimalFormat; public class Misol1001{ public static void main(String[]args){ Scanner i=new Scanner(System.in); DecimalFormat df = new DecimalFormat("#.####"); df.setRoundingMode(RoundingMode.CEILING); int a=i.nextInt(); long[] k=new long[a]; for(int j=0; j<a; j++){ k[j]=i.nextLong(); } double[] l=new double[a]; for(int c=0;c<a; c++){ l[c]=Math.sqrt(k[c]); } for(int j=a-1; j>=0; j--){ System.out.println(df.format(l[j])); } } } Why i am getting Runtime error (access violation) in test case 9? Edited by author 21.07.2020 19:22 Edited by author 21.07.2020 19:22 #include <iostream> #include <math.h> #include <vector> #include <stdlib.h> using namespace std; int main() { vector<double> v; int v1; while((cin>>v1)) { v.push_back(v1); } int size = v.size(); int first = v[0]; int last = v[size-1]; for(int i = size-1; i>=0; i--) { double a = sqrt(v[i]); printf("%.4lf\n", a); } return 0; } a = list(map(int,input().split())) n = len(a) for i in range(n-1,-1,-1): print("%.4f" % pow(a[i],1/2)) pow(a,b) in Python means the power of integer a and integer b (a^b) use a**b in Python instead. import java.util.*; public class ReverseRoot { public static void main(String[] args) { ArrayList<Long> list = new ArrayList<>(); Scanner scn = new Scanner(System.in); while (scn.hasNextLong()) { long p = scn.nextLong(); list.add(p); } scn.close(); for (int i = list.size() - 1; i >= 0; i--) { System.out.printf("%.4f%n", Math.sqrt((double) list.get(i))); } } } Edited by author 17.02.2021 15:27 Scanner scn = new Scanner(System.in); long p; String line; while (!(line = scn.nextLine()).trim().equals("")) { p = Long.parseLong(line); list.add(p); } |
|
|