Ladder Supplement

Valentine's Day


Insert picture description here

The above is a wonderful post in the circle of friends: "It's Valentine's Day on February 14th, and I decided to benefit everyone. For the 2nd and 14th likes, I will introduce you to know... Let's eat three... You two invite... ". Here is a list of friends who liked this post. Please find out the two hapless guests who want to treat.

Simple questions, good ideas

Input format:

Enter the names of people who do not know how many likes are given in the order of the likes. Each person's name occupies a line and is a non-empty word with no more than 10 English letters, and ends with a carriage return. An English period. Marks the end of input. This symbol is not included in the like list.

Output format:

Output the conclusion in one line according to the like situation: if there is the first 2person Aand the first 14person B, then output “A and B are inviting you to dinner...”; if there are Anone B, then output “A is the only one for you...”; if Athere are none, then output “Momo... No one is for you ...”.

Input example 1:

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

Output sample 1:

Magi and Potaty are inviting you to dinner...

Input example 2:

LaoLao
FatMouse
whoever
.

Output sample 2:

FatMouse is the only one for you...

Input sample 3:

LaoLao
.

Output sample 3:

Momo... No one is for you ...

Note:
In fact, there is a misunderstanding, that is, to open a two-dimensional array to store all the input strings. It is too stupid. According to the question, we only need to store the second and fourteenth strings. The problem is not difficult, but this idea of ​​solving the main contradiction is very important

Code

#include<bits/stdc++.h>
using namespace std;
string yi, er, a;
int flag1, flag2, res;
int main()
{
    
    
    while(cin >> a)
    {
    
    
        if(a == ".") break; //注意这里不是'.'而是".";
        res ++ ;
        if(res == 2 )
        {
    
    
            flag1 = 1;
            yi = a;
        }
        else if(res == 14 )
        {
    
    
            flag2 = 1;
            er = a;
        }
    }
    if(flag1 && flag2 ) cout << yi << " and " << er << " are inviting you to dinner..." << endl;
    else if(flag1 && !flag2) cout << yi <<" is the only one for you..." << endl;
    else cout << "Momo... No one is for you ..." << endl;   
    return 0;
}

A small note : the string in c++ cannot be used for printfoutput, it can only be used for cout << "" << endl;output

Sum of N numbers



Question stem: The requirement of this question is very simple, that is, find the sum of N numbers. The trouble is that these numbers are given in the form of the numerator/denominator of a rational number, and the sum you output must also be in the form of a rational number.

Input format:

Enter the first line to give a positive integer N (≤100). The following line gives N rational numbers in the format a1/b1 a2/b2... Make sure that all numerators and denominators are within the long integer range. In addition, the sign of a negative number must appear in front of the numerator.
Output format:

The simplest form of outputting the above number sum-that is, the result is written as an integer part of the fraction, where the fraction is written as a sub/denominator. The numerator is required to be smaller than the denominator, and they have no common factor. If the integer part of the result is 0, only the fractional part is output.
Input example 1:

5
2/5 4/15 1/30 -2/60 8/3

Output sample 1:

3 1/3

Analysis: Violent method
Code:

#include<bits/stdc++.h>
using namespace std;
long long int fz, fm, resfz, resfm;
long long int n;
int main()
{
    
    
    cin >>n;
    for(int i = 0; i < n; i ++ )
    {
    
    
        scanf("%lld/%lld", &fz, &fm);
        if(i == 0)
        {
    
    
            resfz = fz;
            resfm = fm;
        }
        else
        {
    
    
            resfz = fm * resfz + fz * resfm;
            resfm = resfm * fm;
        }
        for(long long int i = 2; i <= max(resfm, resfz); i ++ )
        {
    
    
            while (resfz % i == 0 && resfm % i == 0)
            {
    
    
                resfz /= i;
                resfm /= i;
            }
        }
    }
    long long int z = resfz / resfm;
    resfz %= resfm;
    for(long long int i = 2; i <= max(resfz, resfm); i ++ )
    {
    
    
        while (resfz % i == 0 && resfm % i == 0)
        {
    
    
            resfz /= i;
            resfm /= i;
        }
    }
    if(z && resfz) cout << z << " " << resfz << "/" << resfm << endl;
    else if(z && !resfz) cout << z << endl;
    else if(!z && resfz) cout << resfz << "/" << resfm << endl;
    else if(!z && !resfz) cout << 0 << endl;
    return 0;
}

Note: The input process is mixed with the process of passing points. While inputting, first add violently, and then use the for loop to reduce violently.

Nth string from the bottom

Problem Description:

Given a string arithmetic entirely composed of lowercase letters increasing sequence, each string in the sequence is fixed L, from La astart to 1increment in steps. When, for example, Lit is 3when the sequence { aaa, aab, aac, ..., aaz, aba, abb, ..., abz, ..., zzz }. The penultimate 27string of this sequence is zyz. For any given L, this question requires you to give the corresponding penultimate sequence Nstring.

Input:

Input given two positive integers in a row L(2 <= L <= 6)and N(<= 105).

Output:

Output the Nlast character string of the corresponding sequence in one line . The title guarantees that this string exists.

Sample Input:

3   7417

Sample Output:

pat

Analysis:
1. Enter n digits, then the total number of permutations obtained at the end is 2 6 n 26^n26n
2. The total number of orders is known asm, and the last required number is also known. It is26^n-mrecorded as the required positive number order, which is used here toxindicate
3.xAdd the result obtained by calculating the remainderwithrespect to 26 You'a'can get what the last letter is from the above. Each time the overall sequence number is reduced by 26, it is the letter in the next position, and so on, the code is as follows:

My solution

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+10;
char a[N];
long long int flag, x, y, l, n, m = 1;
int main()
{
    
    
    cin >> l >> n;
    for(int i = 0; i < l; i ++ )m *= 26;
    n = m - n;
    flag = l;
    while(l -- )
    {
    
    
        x = n % 26;
        a[l] = 'a' + x;
        n /= 26;
    }
    for(int i = 0; i < flag; i ++ ) cout << a[i];
}

People in groups


Question:
We have defined an "activity" for everyone in social networks. Now we hope to divide the population into two categories based on this indicator, namely outgoing (highly active) and introverted (that is, Low activity).
It is required that the size of the two groups of people be as close as possible, and the gap between their total activity is as wide as possible.

Input format:

Enter the first line to give a positive integer N(2≤N≤10​5​​). The next line gives Na positive integer, which is the activity of each person, separated by a space. The title guarantees that these numbers and their sum will not exceed 2​^31​​.

Output format:

Output in the following format:

Outgoing #: N1
Introverted #: N2
Diff = N3

Among them N1is the number of extroverts; N2is the number of introverts; N3is the absolute value of the difference between the total activity of the two groups.

Input example 1:

10
23 8 10 99 46 2333 46 1 666 555

Output sample 1:

Outgoing #: 5
Introverted #: 5
Diff = 3611

Idea: Take the middle value midas the dividing line, the left half is the introvert, and the right half is the extrovert. Due to the large amount of data, there will be two test points timeout when using bubbling, and sort(a, a + n)you can use the function to process it.

My Solution

#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int a[N];
int sum1, sum2, mid, ans, r;
int main()
{
    
    
    cin >> n;
    for(int i = 0; i < n; i ++ ) cin >> a[i];
    sort(a, a + n);
    mid = n / 2;
    r = n - mid;
    for(int i = 0; i < mid; i ++ )
    {
    
    
        sum1 += a[i];
    }
    for(int i = mid; i < n; i ++)
    {
    
    
        sum2 += a[i];
    }
    ans = sum2 - sum1;
    cout << "Outgoing #: " << r << endl;
    cout << "Introverted #: " << mid << endl;
    cout << "Diff = " << ans << endl;
}

Guess you like

Origin blog.csdn.net/qq_51960163/article/details/115219547