FMK-LOG

Решение задачи 1

#include <stdio.h>
#include 
#include 
#include 
#include 

void get_data(void);


FILE *in, *out;
char name[255],s[255];
char monitor[255],block[255],keyboard[255];
int  m_price, b_price, k_price, m_min, b_min, k_min, i;

void main(void)
{
   if ((in = fopen("INPUT.TXT", "rt")) == NULL)
    {
      fprintf(stderr, "Cannot open input file.\n");
      return;
    }
   get_data();
   sprintf(monitor,"%s %d",name,m_price); m_min=m_price;
   sprintf(block,"%s %d",name,b_price); b_min=b_price;
   sprintf(keyboard,"%s %d",name,k_price); k_min=k_price;
   while(!feof(in))
   {
    get_data();
    if (m_min>m_price)
     {
      sprintf(monitor,"%s %d",name,m_price); m_min=m_price;
     }
    if (b_min>b_price)
     {
      sprintf(block,"%s %d",name,m_price); b_min=b_price;
     }
    if (k_min>k_price)
     {
      sprintf(keyboard,"%s %d",name,k_price); k_min=k_price;
     }
   }
   if ((out = fopen("OUTPUT.TXT", "wt")) == NULL)
   {
      fprintf(stderr, "Cannot open output file.\n");
      return;
   }
   fprintf(out,"‘Ёб⥬­л© Ў«®Є %s\n",block);
   fprintf(out,"Њ®­Ёв®а %s\n",monitor);
   fprintf(out,"Љ« ўЁ вга  %s\n",keyboard);
   fprintf(out,"€в®Ј®: %d\n",m_min+b_min+k_min);
   fclose(out);
}

void get_data(void)
{
 int price,l=0;
  fgets(name,255,in);
  name[strlen(name)-1]=0;
 while (l++<3)
 {
  fgets(s,255,in);
  price=atoi(strrchr(s,' '));
  switch (s[0]) {
   case 'Њ': m_price=price; break;
   case '‘': b_price=price; break;
   case 'Љ': k_price=price; break;
  }
 }
}


Тесты к задачам по информатике




Сайт создан в системе