Чтобы распечатать сведения о кинотеатрах при наличии названия фильма с использованием файлов для хранения информации о кинотеатре, вы можете использовать различные методы на разных языках программирования. Вот несколько примеров на Python, Java и C++:
Метод 1: Python
def print_theater_details(movie_name):
with open('theater_details.txt', 'r') as file:
for line in file:
theater_name, movie_names, location = line.split(',')
movie_names = movie_names.strip().split(';')
if movie_name in movie_names:
print(f"Theater Name: {theater_name}")
print(f"Location: {location}")
movie_name = input("Enter the movie name: ")
print_theater_details(movie_name)
Метод 2: Java
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class TheaterDetails {
public static void printTheaterDetails(String movieName) {
try (BufferedReader reader = new BufferedReader(new FileReader("theater_details.txt"))) {
String line;
while ((line = reader.readLine()) != null) {
String[] theaterInfo = line.split(",");
String theaterName = theaterInfo[0].trim();
String[] movieNames = theaterInfo[1].trim().split(";");
String location = theaterInfo[2].trim();
for (String name : movieNames) {
if (name.equals(movieName)) {
System.out.println("Theater Name: " + theaterName);
System.out.println("Location: " + location);
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
String movieName = "Enter the movie name"; // Replace with user input
printTheaterDetails(movieName);
}
}
Метод 3: C++
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
struct Theater {
std::string name;
std::vector<std::string> movies;
std::string location;
};
void printTheaterDetails(const std::string& movieName) {
std::ifstream file("theater_details.txt");
std::string line;
std::vector<Theater> theaters;
while (std::getline(file, line)) {
std::stringstream ss(line);
std::string theaterName, movieNames, location;
std::getline(ss, theaterName, ',');
std::getline(ss, movieNames, ',');
std::getline(ss, location, ',');
std::stringstream movieStream(movieNames);
std::string movie;
std::vector<std::string> movies;
while (std::getline(movieStream, movie, ';')) {
movies.push_back(movie);
}
theaters.push_back({ theaterName, movies, location });
}
for (const Theater& theater : theaters) {
for (const std::string& movie : theater.movies) {
if (movie == movieName) {
std::cout << "Theater Name: " << theater.name << std::endl;
std::cout << "Location: " << theater.location << std::endl;
break;
}
}
}
}
int main() {
std::string movieName;
std::cout << "Enter the movie name: ";
std::getline(std::cin, movieName);
printTheaterDetails(movieName);
return 0;
}
Эти методы считывают сведения о кинотеатре из файла (theater_details.txt), который содержит строки в формате «Название театра, Названия фильмов, Местоположение». Каждое название фильма отделяется точкой с запятой (;). Затем код ищет заданное название фильма и выводит соответствующую информацию о кинотеатре.