Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Pensia ( 14 years ago )
// Pasha_z1.cpp: определяет точку входа для консольного приложения.
//

#include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include "iostream"
using namespace std;


int comp (const void * a, const void * b) 
{ 
return ( *(int*)a - *(int*)b ); 
} 
char s;
int i=0,a[1000],k,n,sum=0,j;

int _tmain(int argc, _TCHAR* argv[])
{
 std::fstream stream;
 std::ofstream stream2;
 stream2.open("DIV.OUT");

 stream.open("DIV.IN");
 while(!(stream.eof())) //пока не конец файла 
 { 
  stream>>s; //считываем итый элемент массива
  a[i]=s-48;
  sum=sum+a[i];
  ++i;
 }
 i--;
 sum=sum-a[i];
 n=i;
 k=0;
 if ((sum % 3)!=0) 
  if ((sum % 3)==1) 
  {
   for (i=0;i<n;i++)
    if (a[i]==1) {sum=sum-a[i]; a[i]=0; k++; break;}
  }
  else
  {
   for (i=0;i<n;i++) 
    if (a[i]==2) {sum=sum-a[i]; a[i]=0; k++; break;}
  }

  if ((sum % 3)==0)
  {
  qsort(a,n,sizeof(int),comp);
  
  if (a[k]!=0 && a[k]!=5) 
   for (i=k;i<n;i++) 
    if (a[i]==5) 
    {
     for (j=i;j>0;j--)
      a[j]=a[j-1];
     a[k]=5;
     break;

    }

   for (i=n-1;i>k-1;i--)
    stream2<<a[i];

  }

  else stream2<<"невозможно";


 stream2.flush();

 stream.close();
 stream2.close();
 return 0;
}

 

Revise this Paste

Your Name: Code Language: