All pastes #237638 Raw Edit

Someone

public text v1 · immutable
·published 2006-11-04 17:50 UTC
rendered paste body
#include <cstdlib>
#include <iostream>
#include<math.h>
#include<cstdio>
#define MAX 1000000000
using namespace std;

int *wynik;
int N;

void Wczytaj(int k)
{
     int a,b;
     int suma=0;
     for(int i=0;i<9;i++)
     {
     scanf("%d%d",&a,&b);
     suma*=10;
     suma+=a+b;
     }
 wynik[k]=suma;  
     
}

void Koniec(int k)
{
 int a,b;
 int suma=0;
 for(int i=0;i<N%9;i++)
 {
 scanf("%d%d",&a,&b);
 suma*=10;
 suma+=a+b;
 }
   if(suma/pow(10,N%9))
     {
      wynik[k-1]+=1;
      wynik[k]=suma % (int)pow(10,N%9);
     }
     else
   wynik[k]=suma; 
     
}
void Sprawdz(int k)
{
     if(wynik[k]/MAX)
     {
     wynik[k]=wynik[k]%MAX;
     wynik[k-1]+=1;
     }
}  
void Wypisz(int i)
{
  int pom=MAX/10;
   while(wynik[i]/pom==0)
   {
   printf("0");
   pom/=10;
   }
 printf("%d",wynik[i]);
}
void WypiszKoniec(void)
{
 
    int pom=pow(10,N%9-1);
    while(wynik[N/9]/pom==0)
    {
    printf("0");
    pom/=10;
    }
     printf("%d",wynik[N/9]);
} 
int main(int argc, char *argv[])
{
   int pom;
  
    scanf("%d",&N);
    pom=N%9;
    if(pom!=0)
    wynik=new int[N/9+1];
    else
    wynik=new int[N/9];
    for(int k=0;k<N/9;k++)
    Wczytaj(k);
    if(pom!=0)
    Koniec(N/9);
    for( k=N/9-1;k>=0;k--)
    Sprawdz(k);
    for( k=0;k<N/9;k++)
    Wypisz(k);
    if(pom!=0)
    WypiszKoniec();
    delete []wynik;        
   return EXIT_SUCCESS;
}