Openjudge - alignment output

Openjudge - alignment output

describe

Read in three integers, and output them right-aligned according to the width of each integer of 8 characters.

enter

Only one line, containing three integers separated by a space.

output

There is only one line, and three integers are output sequentially according to the format requirements, separated by a space.

sample input

123456789 0 -1

sample output

123456789        0       -1

source code

#include<iostream>
#include<iomanip>

using namespace std;

int main()
{

    int a,b,c;
    cin>>a>>b>>c;
    cout<<setiosflags(ios::right)
    <<setw(8)<<a<<' '
    <<setw(8)<<b<<' '
    <<setw(8)<<c<<' '
    <<endl;
    return 0;
}

analyze:

The topic has 3 requirements:

1. Each integer occupies a width of 8 characters, use setw(8) to set the width of characters

2. Use setiosflags(ios::left/right) for left/right alignment, but remember to add header files

3. Output three integers separated by a space

Guess you like

Origin blog.csdn.net/Duba_zhou/article/details/125861377