Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class pr1 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String line = sc.nextLine();
- Map<String, List<String>> bandMembers = new LinkedHashMap<>();
- Map<String, Integer> bandTime = new HashMap<>();
- int totalTime = 0;
- while(!line.equals("start of concert")){
- String[] tokens = line.split("; ");
- if(tokens[0].equals("Add")){
- String bandName = tokens[1];
- String[] members = tokens[2].split(", ");
- if(!bandMembers.containsKey(bandName)) {
- bandMembers.put(bandName, new ArrayList<>());
- }
- for (int i = 0; i < members.length; i++) {
- if(!bandMembers.get(bandName).contains(members[i])){
- bandMembers.get(bandName).add(members[i]);
- }
- }
- }else{
- String bandName = tokens[1];
- int time = Integer.parseInt(tokens[2]);
- bandTime.putIfAbsent(bandName, 0);
- bandTime.put(bandName, bandTime.get(bandName) + time);
- totalTime += time;
- }
- line = sc.nextLine();
- }
- String band = sc.nextLine();
- System.out.println("Total time: " + totalTime);
- bandTime.entrySet().stream()
- .sorted(Map.Entry.<String, Integer>comparingByValue().reversed()
- .thenComparing(Map.Entry.comparingByKey()))
- .forEach(e -> System.out.printf("%s -> %d%n", e.getKey(), e.getValue()));
- System.out.println(band);
- bandMembers.get(band).stream()
- .forEach(e -> System.out.println("=> " + e));
- }
- }
- ======================================================================================================================
- import java.util.Scanner;
- public class pr2 {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String line = sc.nextLine();
- while(!line.equals("end")){
- String result = "";
- String[] tokens = line.split(":");
- String artist = tokens[0];
- String song = tokens[1];
- int key = artist.length();
- if(artistIsValid(artist) && songIsValid(song)){
- for (int i = 0; i < artist.length(); i++) {
- char symbol = (char)(artist.charAt(i) + key);
- if((char)(artist.charAt(i) + key) > 'z') {
- symbol = (char)((char)(symbol - 'z') + '`');
- result += symbol;
- }else if ((char)(artist.charAt(i) + key) > 'Z'
- && (char)(artist.charAt(i) + key) < 'a') {
- symbol = (char)((char)(symbol - 'Z') + '@');
- result += symbol;
- }else {
- if (artist.charAt(i) == '\'' || artist.charAt(i) == ' ') {
- result += artist.charAt(i);
- } else {
- result += symbol;
- }
- }
- }
- result += "@";
- for (int i = 0; i < song.length(); i++) {
- char symbol = (char) (song.charAt(i) + key);
- if((char)(song.charAt(i) + key) > 'z') {
- symbol = (char)((char)(symbol - 'z') + '`');
- result += symbol;
- }else if ((char)(song.charAt(i) + key) > 'Z') {
- symbol = (char)((char)(symbol - 'Z') + '@');
- result += symbol;
- }else {
- if (song.charAt(i) == ' ') {
- result += song.charAt(i);
- } else {
- result += symbol;
- }
- }
- }
- System.out.println("Successful encryption: " + result);
- }else{
- System.out.println("Invalid input!");
- }
- line = sc.nextLine();
- }
- }
- private static boolean songIsValid(String song) {
- for (int i = 0; i < song.length(); i++) {
- if(Character.isLowerCase(song.charAt(i)) && song.charAt(i) != ' '){
- return false;
- }
- }
- return true;
- }
- private static boolean artistIsValid(String artist) {
- if(Character.isLowerCase(artist.charAt(0))){
- return false;
- }
- for (int i = 1; i < artist.length(); i++) {
- if(Character.isUpperCase(artist.charAt(i))){
- return false;
- }
- if(!Character.isLetter(artist.charAt(i)) && artist.charAt(i) != '\''
- && artist.charAt(i) != ' '){
- return false;
- }
- }
- return true;
- }
- }
- =======================================================================================================================
- package softuni.bandregister.entities;
- import javax.persistence.*;
- @Entity
- @Table(name = "bands")
- public class Band {
- private Integer id;
- private String name;
- private String members;
- private Double honorarium;
- private String genre;
- public Band(String name, String members, Double honorarium, String genre) {
- this.name = name;
- this.members = members;
- this.honorarium = honorarium;
- this.genre = genre;
- }
- public Band() {
- }
- @Id
- @GeneratedValue(strategy = GenerationType.IDENTITY)
- public Integer getId() {
- return id;
- }
- public void setId(Integer id) {
- this.id = id;
- }
- @Column(nullable = false)
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- @Column(nullable = false)
- public String getMembers() {
- return members;
- }
- public void setMembers(String members) {
- this.members = members;
- }
- @Column(nullable = false)
- public Double getHonorarium() {
- return honorarium;
- }
- public void setHonorarium(Double honorarium) {
- this.honorarium = honorarium;
- }
- @Column(nullable = false)
- public String getGenre() {
- return genre;
- }
- public void setGenre(String genre) {
- this.genre = genre;
- }
- }
- package softuni.bandregister.bindingModels;
- public class BandBindingModel {
- private String name;
- private String members;
- private Double honorarium;
- private String genre;
- public BandBindingModel(){}
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getMembers() {
- return members;
- }
- public void setMembers(String members) {
- this.members = members;
- }
- public Double getHonorarium() {
- return honorarium;
- }
- public void setHonorarium(Double honorarium) {
- this.honorarium = honorarium;
- }
- public String getGenre() {
- return genre;
- }
- public void setGenre(String genre) {
- this.genre = genre;
- }
- }
- package softuni.bandregister.controllers;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.PathVariable;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.servlet.ModelAndView;
- import softuni.bandregister.bindingModels.BandBindingModel;
- import softuni.bandregister.entities.Band;
- import softuni.bandregister.repositories.BandRepository;
- import java.util.ArrayList;
- import java.util.List;
- @Controller
- public class BandController {
- private final BandRepository bandRepository;
- @Autowired
- public BandController(BandRepository bandRepository) {
- this.bandRepository = bandRepository;
- }
- @GetMapping("/")
- public ModelAndView index(ModelAndView modelAndView) {
- List<Band> bands = bandRepository.findAll();
- modelAndView.setViewName("base-layout");
- modelAndView.addObject("view", "band/index");
- modelAndView.addObject("bands", bands);
- return modelAndView;
- }
- @GetMapping("/create")
- public ModelAndView create(ModelAndView modelAndView) {
- modelAndView.setViewName("base-layout");
- modelAndView.addObject("view", "band/create");
- return modelAndView;
- }
- @PostMapping("/create")
- public String create(Band band) {
- bandRepository.saveAndFlush(band);
- return "redirect:/";
- }
- @GetMapping("/edit/{id}")
- public ModelAndView edit(ModelAndView modelAndView,
- @PathVariable(value = "id") Integer id) {
- Band bandToEdit = bandRepository.getOne(id);
- modelAndView.setViewName("base-layout");
- modelAndView.addObject("view", "band/edit");
- modelAndView.addObject("band", bandToEdit);
- return modelAndView;
- }
- @PostMapping("/edit/{id}")
- public String edit(@PathVariable(value = "id") Integer id, BandBindingModel bandBindingModel) {
- Band bandFromDb = bandRepository.getOne(id);
- bandFromDb.setName(bandBindingModel.getName());
- bandFromDb.setMembers(bandBindingModel.getMembers());
- bandFromDb.setHonorarium(bandBindingModel.getHonorarium());
- bandFromDb.setGenre(bandBindingModel.getGenre());
- bandRepository.saveAndFlush(bandFromDb);
- return "redirect:/";
- }
- @GetMapping("/delete/{id}")
- public ModelAndView delete(ModelAndView modelAndView,
- @PathVariable(value = "id") Integer id) {
- Band bandToDelete = bandRepository.getOne(id);
- modelAndView.setViewName("base-layout");
- modelAndView.addObject("view", "band/delete");
- modelAndView.addObject("band", bandToDelete);
- return modelAndView;
- }
- @PostMapping("/delete/{id}")
- public String delete(Band band) {
- this.bandRepository.delete(band);
- return "redirect:/";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement