Предмет: Информатика, автор: X1337

C++

Напишите программу, которая вводит координаты двух точек на числовой оси и выводит расстояние между ними. Входные данные В первой строке вводятся через пробел координаты первой точки (сначала x -координата, потом y -координата), во второй строке в том же порядке – координаты второй точки. Все координаты – вещественные числа. Выходные данные Программа должна вывести одно число: расстояние между точками с тремя знаками в дробной части.
Примеры
входные данные 1. 1. 2. 2.
выходные данные 1.414

Ответы

Автор ответа: pz4t9v0d4tly
1

#include <iostream>

#include <cmath>

#include <vector>

using namespace std;

int main() {

vector<float> coordinates;

string a;

getline(cin, a);

string buffer;

for(int i = 0; i<a.length(); ++i) {

 if(a[i]!=' ') {

  buffer+=a[i];

 } if(a[i]==' '||i==a.length()-1) {

  if(buffer[buffer.length()-1]=='.') {

   buffer+="0";

  }  

  float num = stof(buffer);

  coordinates.push_back(num);

  buffer = "";

 }

}

if(coordinates.size()!=4) {

 cout << "wrong data. example: 1.1 2.2 3.3 4.4";

}

float result;

int temp1, temp2, temp3, temp4;

temp1 = coordinates[0]-coordinates[2];

temp2 = coordinates[1]-coordinates[3];

temp1 = temp1 * temp1;

temp2 = temp2 * temp2;

temp3 = temp1 + temp2;

result = sqrt(temp3);

cout << result;

}

Похожие вопросы
Предмет: Английский язык, автор: masha21823
1. Раскройте скобки, употребляя глаголы в Future Simple, а затем напишите к предложениям вопросительную и отрицательную форму:
1) I ___ chess tomorrow (to play).
2) Nick ___ to the park next Sunday (to go).
3) You ___ to my place next week (to come).
4) They ___ to Spain next summer (to go).
5) We ___ to the theatre tomorrow (to go).

2. Употребите сравнительную или превосходную степень прилагательных:
1) ___ island in the world is Greenland (big).
2) Healthy people are often ___ than other people who are not fit (happy).
3) It’s ___ than yesterday, isn’t it (hot)?
4) ___ animal is the blue whale (heavy).
5) Swimming is ___ for your health than golf (good).
6) The nightlife in London is ___ than in Oxford (interesting).
7) The Stade de France was ___ stadium in the world (expensive).
8) Your spelling is ___ than mine (bad)!


5. Употребите глаголы во времени Future Simple:
1) - What would you like to eat? - I ___ a burger and chips, please (have).
2) – I can’t lift this suitcase. – Wait! I ___ it for you (do).
3) I ___ two weeks in France (spend).
4) I ___ with some friends of my parents (stay).
5) I ___ medicine next year (study).
6) Maybe I ___ for this company (work).
7) I ___ very much (probably / not / earn).
8) I’m going to the shop now. ___ I ___ you one (buy)?

6. Употребите глаголы во времени Present Simple or Future Simple:
1) I ___ he ___ at the office tomorrow (hope) / (be).
2) When you ___ me back my book (give)?
3) I ___ sure you ___ the music (be) / (like).
4) At this time tomorrow we ___ far from
here (be).
5) Don’t wait for me, I probably ___ late (be).
6) I ___ afraid they ___ you very much (be) / (miss).
7) Where we ___ (meet)?
8) You ___ a lot of interesting things in this journal (find).
9) How long it ___ us to get to the airport (take)?
10) There ___ a lot of traffic and cars ___ very slowly, I ___ we ___ a taxi (be) / (move) / (suppose) / (take) .

7. Поставьте глаголы в скобках в Past Simple или Past Continuous:
1) Chris ___ spaghetti every day last week (eat).
2) When I ___ into the room, two boys ____ football (come) / (play).
3) Peter ___ the TV, but nothing ___ (turn on) / (happen).
4) While we ___ in the park, Mary ___ (run) / (fall over).
5) While I ___ to music, I ___ the doorbell (listen) / (hear).
6) I ___ my pen while I ___ my homework (break) / (do).


9. Поставьте глаголы в скобках в Past Simple или Past Continuous:
Last night I 1) ___ alone at home (be). I 2) ___ on my bed and I 3) ___ TV when I 4) ___ a strange noise (lie) / (watch) / (hear). The noise 5) ___ from the kitchen (come). I 6) ___ downstairs, 7) ___ a heavy vase from the table and 8) ___ for the kitchen (go) / (pick up) / (head). I 9) ___ the door very slowly (open). Then I 10) ___ someone (see). He 11) ___ in the fridge (search). I 12) ___ so frightened that I 13) ___ the vase I 14) ___ and it 15) ___ onto the floor (be) / (drop) / (carry) / (crash). The man 18) ___ towards the door and I 17) ___ his face (turn) / (see). It was my husband!


11. Закончите разделительные вопросы:
1) You are allergic to cats, ________?
2) He didn’t lose the keys, ________?
3) They have already painted the house, ________?
4) She won’t help you, ________?
5) Peter hasn’t got a new car, ________?
6) Tom works at the hospital, ________?
7) John spoke to Nick, ________?
12. Задайте вопросы к выделенным словам:
1) This happened yesterday.
2) He was wearing a large hat.
3) She lives in a big house in California.
4) She goes to the cinema twice a week.
5) At the moment she is visiting Italy.
6) She became a star because she could sing so well.
7) This year she has visited ten different countries.
Предмет: Английский язык, автор: aygerimalzhanova
Предмет: Алгебра, автор: arina05