Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.3 kB
0
Indexable
Never
#include <iostream>
#include <vector>
#include<string>
#include <iomanip>
using namespace std;

int main()
{
    int n,ch;n=0;
    int num=0;ch=1;
    vector<int>matrix;
    string line;
    line={' '};

    while(getline(cin,line))
    {
           int i=0;num=0;ch=1;
           if(line[0]=='z')
           {
               break;
           }
           for(int i=0;i<line.length();i++)
           {
               if(line[i]!=' '&&line[i]!='-')
               n=n*10+static_cast<int>(line[i])-static_cast<int>('0');
               else if(line[i]=='-')
                ch=-1;
               else if(line[i]==' ')
               {
                    n=n*ch;
                    matrix.push_back(n);
                    n=0;ch=1;num++;
               }


           }
           n=n*ch;
           matrix.push_back(n);num++;



        for(int x=1;x<num;x++)
        {
            int Insert=matrix[x];
            int moveitem=x;
            while(matrix[moveitem]>matrix[moveitem+1]&&moveitem>0)
            {
                matrix[moveitem+1]=matrix[moveitem];
                moveitem++;
            }
            matrix[moveitem]=Insert;
        }

        for(int n=0;n<num;n++)
        {
            cout << matrix[n]<<" " ;
        }
    }
    return 0;
}


Leave a Comment