回答 1 已采纳 Description
"There are a thousand Hamlets in a thousand people's eyes."
Lotus is a big fan of Shakespeare. Her favorite tragedy written by Shakespeare is Hamlet, one of the most popular works in English language. However, since Lotus is really a merciful and kindhearted girl, she doesn't like the scene of the final match, in which Hamlet fenced against Laertes. Once she had a dream of Hamlet. In that dream, Hamlet fought with Laertes in another way: flipping coins.
It sounds like gambling. In order to flip the coin in an absolutely fair way, Hamlet got a monkey to do this job instead of people. Before the monkey started to flip, Hamlet and Laertes respectively wrote down an arbitrary sequence of results (we call it a "pattern"). For example, Hamlet wrote down "Head, Tail, Head" while Laertes wrote down "Head, Head, Tail, Tail".It was guaranteed that the pattern of Hamlet's did not occur within the pattern of Laertes', nor did the pattern of Laertes' occur within the pattern of Hamlet's. Then the monkey began to flip the coin over and over and generated a sequence of results, like "Head, Head, Tail, Head, Tail ..." At any time, if the monkey obtained Hamlet's pattern, it stopped flipping and Hamlet won. Otherwise, if the monkey obtained Laertes's pattern, it also stopped flipping and Laertes won.
One example of the gambling is like following: Hamlet's pattern was ""HHT" (H=Head, T=Tail) and his rival's pattern was "HTTT". The monkey flipped the coin and obtained "H, T, H, T, T, H, T, T, T". At that time, Laertes' pattern appeared at the end of the sequence, so the monkey stopped and the judge declared that Laertes won the game.
Now your task is to decide that in Lotus' gambling, who has the higher probability to win the game. Pay attention that since the monkey has no bias, the probabilities to get head or tail in one flip are always equal.
The input contains several test cases. The first line of each case contains two positive integers N and M (0 < N, M <= 100000). N is the length of Hamlet's pattern and M is the length of Laertes'.
The second line contains a string of length N, representing the pattern of Hamlet's. The third line contains a string of length M, representing the pattern of Laertes'. All the strings only contain uppercase letters `H' and `T'. The input ends by a line of two zeros.
For each test case, output a single line to show your answer. If Hamlet has a better chance to win, output the word 'Hamlet'. If Laertes has a better chance, output the word 'Laertes'. If they have the same probability to win the game, output the word 'Equal'.
回答 1 已采纳 Description
Dave Johnson is a book collector. Over the years, he collected so many books that he decided he needed to buy some new bookcases. He bought enough cases, of different quality, to fit all of his books. One problem remained, however. He wanted to put his favorite books in a special display on the top shelf of his best bookcase. This shelf is wide enough to fit at most 10 books.
This would normally be an easy task, but Dave is particular about the way he displays his favorite books. Not only must they be sorted alphabetically by title, but also there must never be two books next to each other that have the same letter in the same position in the title. Note that Dave looks only at alphabetical characters in the titles of his books, skipping spaces, apostrophes, etc., and he ignores the case of the letters. Thus, in the title "Portnoy's Complaint", 's' is the 8th character, and 'c' is the 9th character. As an example, "The Grapes Of Wrath" and "One Flew Over The Cuckoo's Nest" cannot be next to each other since the third letter of each title is the letter 'e'.
In order to help make this decision, Dave has assigned an emotional value to each of his books. Given a list of titles and the emotional value of each book, your job is to help Dave decide which books should go on his top shelf so as to maximize the total emotional value of all of the books.
There will be one test case in each input file. The first line will contain an integer N (10 <= N <= 2500), specifying the number of books that are candidates for Dave's top shelf. The next N lines will each contain an integer E and a string S, separated by a single space. E is an integer no larger than 200 that represents the emotional value for Dave of the book with title S. Note that S can have an arbitrary number of spaces, but will not exceed 30 characters. S is guaranteed to contain at least one alphabetical character. Input should be read from stdin.
The first line of the output should contain an integer M giving the number of books on Dave's top shelf. The second line should give the total emotional value of all of the books on the shelf. The next M lines should give the titles of the books on the shelf, in lexicographic order. If there is more than one solution, any one will do. Output should be written to stdout.
117 The Pearl
100 War And Peace
55 The Prince
175 Of Mice And Men
200 The Grapes Of Wrath
87 For Whom The Bell Tolls
10 Oliver Twist
50 Snow Crash
110 Great Expectations
For Whom The Bell Tolls
Of Mice And Men
The Grapes Of Wrath
War And Peace
回答 2 已采纳
I'm trying something out in php, didn't used him a couple of years ago, so I want to start learning it quite much these days. But I don't like learning it through the books and w3school, I want to learn it through basic use of it, the most common task and such.
Well I have a question, and that would be how to use php to print the whole table inside the database.
I have made a database in my local sql server, and modified the tables through phpmyadmin. Here is how it is:
Table : books
In table of books I have 11 coulmns, i have a primary key assigned as book_id. I want to make my output like for every book_id all values of other columns.
rating 9.8 very good
author William Shakespeare
and so on.
Here is my sql SELECT inside php
$host = "localhost";
$user = "admin";
$db = "bookstore";
$conn = mysqli_connect($host,$user,$pass,$db) or die("Error " . mysqli_error($link));
$sql = "SELECT book_id, title, genre, rating, description, author, author_rating, author_description, author_id FROM books" or die("Error in the consult.." . mysqli_error($link));
$result = mysqli_query($sql);
and now please tell me how to move forward to output this selection to page.