|
|
#include <iostream> #include <vector> #include <cmath> using namespace std; int main() { double number; vector<double> numbers; while (cin >> number) numbers.push_back(number); cout.precision(4); cout.setf(std::ios::fixed); for (auto iter = numbers.rbegin(); iter != numbers.rend(); ++iter) cout << sqrt(*iter) << endl; return 0; } //please tell me what's wrong, cause i cant understand... #include <bits/stdc++.h> #include<fstream> #define all(a) (a).begin(), (a).end() #define ll long long #define sz size #define dbl double #define vll vector <ll> #define INF LLONG_MAX #define uniq(x) x.resize(unique(begin(x),end(x))-begin(x)) #define forik(i,m,n) for(ll i=m;i<n;++i) #define re return using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); vll numbers; ll num; while (cin >> num) { numbers.push_back(num); } for (ll i = numbers.size() - 1; i >= 0; i--) { dbl nek = sqrt(numbers[i]); cout << fixed << setprecision(4) << nek << endl; } re 0; } #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. #include <iostream> #include <algorithm> #include <iomanip> #include <string> #include <vector> #include <cmath> using namespace std; int main() { double element, a; vector<double> numbers; while (cin >> element) { numbers.push_back(element); } reverse(numbers.begin(), numbers.end()); for (size_t i = 0; i != numbers.size(); i++) { a = sqrt(numbers[i]); cout << setprecision(4) << a << "\n"; } return 0; } Edited by author 11.01.2024 20:23 How can the program recognize when there aren´t more inputs if use python3 ? my program: nums = [int(x) for x in input().split()] nums.reverse() for num in nums: print('{:.4f}'.format(num ** 0.5)) What's wrong? anyone can tell me ,pls Edited by author 29.11.2023 07:42 Edited by author 29.11.2023 07:43 The answer to your question is in the FAQ, page How to write Python solutions. #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 lines = [] for line in stdin: for i in range(0, len(line.split())): lines.append(line.split()[i]) lines = [int(i) for i in lines] lines_rev = list(reversed(lines)) numbers = [] for i in range(0, len(lines_rev)): numbers.append(lines_rev[i]**0.5) for i in range(len(numbers)): print(f"{numbers[i]:.4f}") 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 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 <bits/stdc++.h> using namespace std; int main(){ long long n, res; vector <long long> vt; while(cin>>n){ vt.push_back(n); } int len = vt.size();
for(int i = len-1; i >= 0; i--){ double n = sqrt(vt[i]); printf("%0.4lf\n", n); } return 0; } Edited by author 07.09.2019 11:05 Edited by author 07.09.2019 11:11 while(cin>>n) .... Its an infinite loop. My AC solution also used while (cin >> n) double instead of long long while declaring n and vector. 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 <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; } } * deleted * Edited by moderator 23.07.2022 20:33 We need a ranking for the least amount of code. I think It doesn't matter. Algorithm is important! Thanx a lot! I didn't know how to read all lines from console! Edited by author 17.07.2022 17:39 #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) } } I investigated on internet, but most of the answers were putting a type of character that breaks the cycle, but in the input example there´s no character and it´s not enough with a "while(cin >> n)" pls help if copypast test text, it read a blank string as EOF by some reason Edited by author 26.02.2022 22:11#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 |
|
|