Cod sursa(job #2401655)

Utilizator stefan24Sandor Stefan stefan24 Data 9 aprilie 2019 21:41:37
Problema A+B Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;
ifstream f("joc.in");
ofstream g("joc.out");
int sumcif(int x)
{
    int x1,y,s=0,nr;
    x1=x;
    while(x1!=0)
    {
        y=x1%10;
        s=s+y;
        x1/=10;
    }
    if(y==s-y)nr=1;
    else nr=0;
    return nr;
}
int n,i,v[40001],nr,x,s,j,aux;
int main()
{
   f>>n;
   for(i=1;i<=n;i++)
   {
       f>>x;
       aux=x;s=0;
       while(aux>9)
       {
           s=s+aux%10;
           aux/=10;
       }
       if(aux==s){j++;v[j]=x;}
   }
   sort(v+1,v+j+1);
   for(i=1;i<=j;i++)
   {
       g<<v[i]<<" ";
   }
}