#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
class pacient {
private:
string lastName_m, mOrFM_m, adress_m, diagnosis_m;
public:
pacient(string lastName = "", string mOrFM = "", string adress = " ", string diagnosis = " ") {
lastName_m = lastName;
mOrFM_m = mOrFM;
adress_m = adress;
diagnosis_m = diagnosis;
}
string getLastName() {
return lastName_m;
}
string getAll() {
return lastName_m + ", " + mOrFM_m + ", " + adress_m + ", " + diagnosis_m + ".";
}
};
int main() {
fstream out("output.txt");
setlocale(LC_ALL, "Russian");
vector<pacient> arr;
for(int i = 0;;++i) {
string a[4];
for(int j = 0; j<4; ++j) {
switch(j) {
case 0: cout << "Last name: "; break;
case 1: cout << "Male or FeMale: "; break;
case 2: cout << "Adress: "; break;
case 3: cout << "Diagnosis: "; break;
}
getline(cin, a[j]);
}
pacient temp(a[0], a[1], a[2], a[3]);
cout << "Для окончания ввода введите 1: ";
arr.push_back(temp);
string temp1;
getline(cin, temp1);
if(temp1=="1") {
break;
}
}
for(int j = 0; j<1000; ++j) {
for(int i = 0; i<arr.size()-1; ++i) {
if(arr[i].getLastName()[0]>arr[i+1].getLastName()[0]) {
swap(arr[i], arr[i+1]);
}
} }
for(int i = 0; i<arr.size(); ++i) {
cout << arr[i].getLastName() << endl;
out << arr[i].getAll();
out << "\n";
}
out.close();
}
Задачка из олимпиады) Простенькая вроде программулька
var
n,i,k,j,f:integer;
m:array [1..100] of string;
p:array[1..100] of string;
sl,por:string;
b:boolean;
f1,f2:text;
begin
assign(f1, 'input.txt');
reset(f1);
readln(f1,n);
for i:=1 to n do
readln(f1,m[i]);
close (f1);
k:=0;
for i:=1 to n do begin
por:='';
b:=false;
sl:=m[i];
for j:=1 to length(sl) do begin
if (Ord(sl[j])>=48) and (Ord(sl[j])<=57) then
por:=por+sl[j];
end;
for f:=1 to k do begin
if por=p[f] then
b:=true;
end;
if b=false then begin
k:=k+1;
p[k]:=por;
end;
end;
assign(f2, 'output.txt');
rewrite(f2);
writeln (f2,k);
for i:=1 to k do
writeln (f2,p[i]);
close (f2);
end.
Объяснение:
Я, а что?