33-Language Primer -33-Inception space

Source: Internet
Author: User
Tags first string pow strcmp

Title address: http://acm.nyist.net/JudgeOnline/problem.php?pid=125?? Description
"Inception" is a wonderful film, in this movie,Cobbso that people can enter the dream, the time in the dream will be much faster than the real time, here assume that the real3minutes, in a dream.1hours.
However,Cobbusing potent sedatives, they can enter a second-level dream from a first-level dream, or even into a three-story, four-story dream, each of which produces the same time-accelerating effect. So now for you .CobbHow long have you been able to figure out the real world through the time you've been dreaming in each layer?
For example,CobbFirst- floor dream.1hours, in the second floor of the dream.1days, and then return to reality immediately after returning to the first level of the dream.
so in the real world, it's actually over.396seconds (6.6minutes)

input
Enter an integer in the first lineT(0<=t<=100)A number that represents the group of test data.
the first line of each set of test data is a numberM (3<=m<=100)
the subsequentMThe beginning of each line of the line is a string that, if the string is"in" theCobbStart with a deeper dream, if it's a string"Out"it meansCobbfrom the deep dream back to the previous layer. If the first string is"Stay"it meansCobbFor a period of time in this layer of dreams, the bank will then be an integerSindicates a stay at that level.Sminutes (1<=s<=10000000). Data assurance in the real world, time is over an integer of a second.
Output
for each set of test data, the time to output the real world (in seconds).
Sample Input
1
6
Inch
Stay 60
Inch
Stay 1440
Out
Out
Sample Output396??? Code: #include <stdio.h>
#include <math.h>
#include <string.h>

static void Handlerdata ();

int main ()
{
???? int readlen = 0;
???? scanf ("%d", &readlen);
???? GetChar ();
????
???? while (Readlen > 0)
???? {
????????? Handlerdata ();
?????????
????????? --readlen;
???? }
????
???? return 0;
}

static void Handlerdata ()
{
???? int readlen = 0;
???? scanf ("%d", &readlen);
????
???? The first floor of a dream
???? int nlevel = 0;
???? Record real world time-minutes
???? Double currtime = 0.0;
????
???? while (Readlen > 0)
???? {
????????? Char infotype[20];
????????? scanf ("%s", InfoType);
????????? if (strcmp (InfoType, "in") = = 0)
????????? {
?????????????? ++nlevel;
????????? }
????????? else if (strcmp (InfoType, "stay") = = 0)
????????? {
?????????????? Double tmpvalue = 0.0;
?????????????? scanf ("%lf", &tmpvalue);
?????????????? Currtime + = Tmpvalue/pow (20,nlevel);
????????? }
????????? else if (strcmp (InfoType, "out") = = 0)
????????? {
?????????????? --nlevel;
?????????????? if (Nlevel < 0)
?????????????? {
??????????????????? Nlevel = 0;
?????????????? }
????????? }
?????????
????????? Line break
????????? GetChar ();
????????? --readlen;
???? }
????
???? Output-seconds unit
???? printf ("%.0f\n", currtime*60);
}


This is not complicated, the main study to the content: 1.math.h pow (A, b)? Calculates the value of the power of a in the 2.string.h strcmp calculates whether two strings are equal 3. For an input line of characters, you can read the contents of an entire line by puts, which can include spaces. And if you use scanf ("%s" ...) Way, when you hit a space, you read a content, which distinguishes between which type of operation (in stay out).

33-Language Primer -33-Inception space

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.