In this article, we will learn what a fluctuating number is and introduce our method of checking whether a given number is a fluctuating number, using a Boolean function to check the fluctuating number.
Problem Statement
We will be given a number and our task is to check if the given number is fluctuating.
Let us first understand the fluctuation number;
A fluctuating number is a number that consists of only two types of numbers, and every other number is the same.
We can say that a fluctuating number is of the form "PQPQPQ", where P and Q are two different numbers in the number system.
The first and second digits of the fluctuation number can never be the same, that is, 11111 is not a fluctuation number.
We usually regard non-trivial fluctuating numbers as fluctuating numbers only, which means that fluctuating numbers need to be composed of at least 3 digits. That is, we can't just use two numbers to form a fluctuating number.
Let us now consider some examples of fluctuating numbers -
494, 484, 474, 464, 454, 434, 424, 414, 404, 393, 383, 373, 363, 353, 343, 323, 313, 303, 101, 121, 131, 141, 151, 161 , 171, 181, 191, 202 and more.
Some high value fluctuating numbers are - 1212121212, 3838383838, 57575757575757, etc.
For any d digit number, where d>=3 (d contains at least 3 digits), we can have 9 * 9 = 81 fluctuating digits, since the first (number from 1 to 9) value has 9 options, similarly to the 9 options (numbers from 0 to 9, except for the first digit).
solution
We have a number and our task is to find out whether it fluctuates or not.
There are some restrictions on numbers −
It contains only two types of numbers.
Two numbers cannot be the same.
Contains at least 3 digits
Adjacent digits in the numbers are not the same.
Example
Given Number : Num = 252 Result: Yes, the number is undulating Given Number : Num = 64664 Result: =No, the number is not undulating
Example
In the following example, we check if the given number is a fluctuating number. We demonstrated using a number that was not a fluctuating number. You can try different numbers to check if the number is a fluctuating number.
#include <bits/stdc++.h> using namespace std; // boolean function that checks // is the number undulating bool Is_number_undulating(string num){ // important to check // if first and second digit // are equal if (num.length() <= 2 || num[0]==num[1]) return false; for (int iterator = 2; iterator < num.length(); iterator++) if (num[iterator - 2] != num[iterator]) false; return true; } int main(){ string num = "111111"; if (Is_number_undulating(num)) cout << " Yes the number is undulating "; else cout << " No, the number is not undulating "; }
Output
When you run the above C program, it will produce the following output -
No, the number is not undulating
Time Complexity - For n digits, the time complexity is O(N).
Space complexity - Since no external space is used, the auxiliary space complexity is O(N).
In this article, we learn in detail what is a fluctuating number and the code solution to check if a given number is fluctuating.
The above is the detailed content of ups and downs numbers. For more information, please follow other related articles on the PHP Chinese website!

C still has important relevance in modern programming. 1) High performance and direct hardware operation capabilities make it the first choice in the fields of game development, embedded systems and high-performance computing. 2) Rich programming paradigms and modern features such as smart pointers and template programming enhance its flexibility and efficiency. Although the learning curve is steep, its powerful capabilities make it still important in today's programming ecosystem.

C Learners and developers can get resources and support from StackOverflow, Reddit's r/cpp community, Coursera and edX courses, open source projects on GitHub, professional consulting services, and CppCon. 1. StackOverflow provides answers to technical questions; 2. Reddit's r/cpp community shares the latest news; 3. Coursera and edX provide formal C courses; 4. Open source projects on GitHub such as LLVM and Boost improve skills; 5. Professional consulting services such as JetBrains and Perforce provide technical support; 6. CppCon and other conferences help careers

C# is suitable for projects that require high development efficiency and cross-platform support, while C is suitable for applications that require high performance and underlying control. 1) C# simplifies development, provides garbage collection and rich class libraries, suitable for enterprise-level applications. 2)C allows direct memory operation, suitable for game development and high-performance computing.

C Reasons for continuous use include its high performance, wide application and evolving characteristics. 1) High-efficiency performance: C performs excellently in system programming and high-performance computing by directly manipulating memory and hardware. 2) Widely used: shine in the fields of game development, embedded systems, etc. 3) Continuous evolution: Since its release in 1983, C has continued to add new features to maintain its competitiveness.

The future development trends of C and XML are: 1) C will introduce new features such as modules, concepts and coroutines through the C 20 and C 23 standards to improve programming efficiency and security; 2) XML will continue to occupy an important position in data exchange and configuration files, but will face the challenges of JSON and YAML, and will develop in a more concise and easy-to-parse direction, such as the improvements of XMLSchema1.1 and XPath3.1.

The modern C design model uses new features of C 11 and beyond to help build more flexible and efficient software. 1) Use lambda expressions and std::function to simplify observer pattern. 2) Optimize performance through mobile semantics and perfect forwarding. 3) Intelligent pointers ensure type safety and resource management.

C The core concepts of multithreading and concurrent programming include thread creation and management, synchronization and mutual exclusion, conditional variables, thread pooling, asynchronous programming, common errors and debugging techniques, and performance optimization and best practices. 1) Create threads using the std::thread class. The example shows how to create and wait for the thread to complete. 2) Synchronize and mutual exclusion to use std::mutex and std::lock_guard to protect shared resources and avoid data competition. 3) Condition variables realize communication and synchronization between threads through std::condition_variable. 4) The thread pool example shows how to use the ThreadPool class to process tasks in parallel to improve efficiency. 5) Asynchronous programming uses std::as

C's memory management, pointers and templates are core features. 1. Memory management manually allocates and releases memory through new and deletes, and pay attention to the difference between heap and stack. 2. Pointers allow direct operation of memory addresses, and use them with caution. Smart pointers can simplify management. 3. Template implements generic programming, improves code reusability and flexibility, and needs to understand type derivation and specialization.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version
SublimeText3 Linux latest version

Atom editor mac version download
The most popular open source editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version
God-level code editing software (SublimeText3)