Search
 
SCRIPT & CODE EXAMPLE
 

CPP

Digits in c++

/*
 Q. Digits
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
Given a number N. Print the digits of that number from right to left separated by space.

Input
First line contains a number T (1 ≤ T ≤ 10) number of test cases.

Next T lines will contain a number N (0 ≤ N ≤ 109)

Output
For each test case print a single line contains the digits of the number separated by space.

Example
inputCopy
4
121
39
123456
1200
outputCopy
1 2 1
9 3
6 5 4 3 2 1
0 0 2 1
*/
//////////////////////////////////////////////////////////////////////////////////////////
//                                solution<1>
/////////////////////////////////////////////////////////////////////////////////////////
#include<iostream>
#include<string>
using namespace std;

int main()
{
	int t, n;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		cin >> n;
		string s = to_string(n);
		for (int j = s.length()-1; j >= 0; j--)
		{
			cout << s[j] << " ";
		}
		cout << "
";
	}
	return 0;
}
//////////////////////////////////////////////////////////////////////////////////////////
//                                solution<2>
/////////////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
 
int main()
{
    int t;
    cin>>t;
    int digit;
    for(int i=0;i<t;i++)
    {
        cin>>digit;
        if(digit==0)
        {
            cout<<0<<endl;
        }else {
        while(digit!=0){
          cout<<digit%10<<" ";
          digit/=10;
        }
        cout<<endl;
    }
    }
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Operatore ternario c++ 
Cpp :: c++ require keyword 
Cpp :: c++ program that put a space in between characters 
Cpp :: what do I return in int main() function c++ 
Cpp :: destiny child 
Cpp :: how to open program in c++ 
Cpp :: Nested ternary operator C++ 
Cpp :: number of characters in string 
Cpp :: unreal engine c++ bind action to function with parameter 
Cpp :: vermífugo significado 
Cpp :: Catcoder mars rover solution in c++ 
Cpp :: C++ meaning :: 
Cpp :: assign array to array 
Cpp :: play roblox vr on quest 2 
Cpp :: converting a string to lowercase inbuld function in cpp 
Cpp :: set keybinding for compiling c++ program in neovim 
Cpp :: displaying m images m windows opencv c++ 
Cpp :: last element of a set in c++ 
Cpp :: generate random ints and floats 
Cpp :: The Three Topics codechef solution in c++ 
Cpp :: partition in STL using vector 
Cpp :: Stream Overloading 
Cpp :: C++ thread header 
Cpp :: determining whether a array is a subsequence of another array 
Cpp :: def minimulHeaviestSetA(arr,n) 
Cpp :: sort 3 numbers using swap cpp 
Cpp :: android call custom managed method from native code 
Cpp :: QMetaObject_invokeMethod 
Cpp :: Integer Literrals in C++ Programming 
Cpp :: Max / Min Stack in c++ using stl in O(1) time and space 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =