ACM training

2019-07-18

09:06:10

er ....

Yesterday, five hours to do a question, mixed feelings, do not worry take your time

Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The ii-th page contains some mystery that will be explained on page aiai (aiiai≥i).

Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page ii such that Ivan already has read it, but hasn't read page aiai). After that, he closes the book and continues to read it on the following day from the next page.

How many days will it take to read the whole book?

The first line contains single integer nn (1n1041≤n≤104) — the number of pages in the book.

The second line contains nn integers a1,a2,,ana1,a2,…,an (iaini≤ai≤n), where aiai is the number of page which contains the explanation of the mystery on page ii.

Print one integer — the number of days it will take to read the whole book.

Input
9
1 3 3 6 7 6 8 8 9
Output
4

Explanation of the example test:

During the first day Ivan will read only the first page. During the second day Ivan will read pages number 22 and 33. During the third day — pages 44-88. During the fourth (and the last) day Ivan will read remaining page number 99.

 

answer:

This question is relatively better, but a little hard to see the problem

Code:

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

ll a[100005]={0};
int main()
{
    ll n;
    ll i;
    scanf("%lld",&n);
    for(i = 1; i <= n; i++)
    {
        scanf("%lld", &a[i]);    
    }
    ll day = 0;
    ll min = 0;
    ll max = 1;
    for(i = 1; i <= n; i++)
    {
        min = i;
        if(a[i] > max)
        {
            max = a[i];
        }
        if(min == max)
        {
            day++;
        }
    }
    cout << day << endl;

    return 0;
} 

Question 2's complicated

Your task is to implement a decoder of the famous Morse alphabet. As most of you know,
the Morse code represents characters as variable-length sequences of short and long signals
(“beeps”), often written as dots and dashes. For those who do not remember their scouting
years, the following table shows the Morse code sequences for all letters:
A .-  E .  I ..  M --  Q --.-  U ..-  Y -.--
B -...  F ..-.  J .---  N -.  R .-.  V ...-  Z --..
C -.-.  G --.  K -.-  O ---  S ...  W .--
D -..  H ....  L .-..  P .--.  T -  X -..-
If more letters are to be transferred, they are separated by a short pause, typically written as
a slash. A space between words is represented by an even longer pause, written as two slashes

 The input contains several test cases. Each test case is specified on one line with at most 1000

characters, which describes a valid Morse code transmission. Specifically:
• The line consists only of dashes (“-”), dots (“.”), and slashes (“/”).
• There is at least one character.
• The first and last characters will never be a slash.
• There will never be more than two slashes together.
• Each non-empty sequence between two slashes contains a valid Morse code of one letter.
For each test case, print one line containing the decoded message in uppercase letters.
.-/-.-./--
-.-./-/..-//---/.--././-.
./-/-././-/./.-./.-//-.../.-././...-/../-/-.--//-.-./..../.-/.-../.-.././-./--./.
The ACM 
CTU the OPEN 
ETNETERA brevity CHALLENGE 

Code:
One problem:
I K assignment mistake, Hey ......
comparison string I should use a [i] == s1.substr (p , lenth); I use Next lead to a false assignment of all sorts, but this question really exercise my ability to write code, I first pass of more than 140 lines of code, uncomfortable cry

#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a[100];
    a[1] = ".-";
    a[2] = "-...";
    a[3] = "-.-.";
    a[4] = "-..";
    
    
    a[5] = ".";
    a[6] = "..-.";
    a[7] = "--.";
    a[8] = "....";
    
    
    a[9] = "..";
    a[10] = ".---";
    a[11] = "-.-";
    a[12] = ".-..";
    
    a[13] = "--";
    a[14] = "-.";
    a[15] = "---";
    a[16] = ".--.";
    
    a[17] = "--.-";
    a[18] = ".-.";
    a[19] = "...";
    a[20] = "-";
    
    
    a[21] = "..-";
    a[22] = "...-";
    a[23] = ".--";
    a[24] = "-..-";
    
    a[25] = "-.--";
    a[26] = "--..";
    string s1;
    while(cin >> s1)
    {
        int p = 0;
        int count = 0;
        for(int i = 0; i < s1.length(); i++)
        {
            if(s1[i] != '/')
            {
                     count++;
                if(i == s1.length() - 1)
                {
                    int sp = 0;
                    for(int j = 1; j <= 26; j++)
                    {
                        if(a[j] == s1.substr(p,count))
                        {
                            printf("%c",65 + j - 1);
                            sp = 1;
                            break;
                        }
                    }
                    if(sp == 1)
                    {
                        cout << endl;
                        break;
                    }
                }
            }
            if(s1[i] == '/')
            {
                    for(int j = 1; j <= 26; j++)
                    {
                        
                        if(a[j] == s1.substr(p,count))
                        {
                            printf("%c",65 + j - 1);
                            p = i+1;
                            count = 0;
                            break;
                        }
                    }
                if(s1[i+1] == '/')
                {
                    cout << " " ;
                    i++;
                    p++;
                }
            }
        }
    } 
}

 

Your task is to implement a decoder of the famous Morse alphabet. As most of you know,
the Morse code represents characters as variable-length sequences of short and long signals
(“beeps”), often written as dots and dashes. For those who do not remember their scouting
years, the following table shows the Morse code sequences for all letters:
A .-  E .  I ..  M --  Q --.-  U ..-  Y -.--
B -...  F ..-.  J .---  N -.  R .-.  V ...-  Z --..
C -.-.  G --.  K -.-  O ---  S ...  W .--
D -..  H ....  L .-..  P .--.  T -  X -..-
If more letters are to be transferred, they are separated by a short pause, typically written as
a slash. A space between words is represented by an even longer pause, written as two slashes

 

Guess you like

Origin www.cnblogs.com/Artimis-fightting/p/11205021.html