Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.65 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define true 1
  4. #define false 0
  5. #define err -2000123000
  6. #define max 9223372036854775807
  7. typedef struct {
  8. double inet,vlc,oth,sms,mms,abr;
  9. }user;
  10. double stod(char s[100])
  11. {
  12.     int i=0,o=false;
  13.     double sm=0;
  14.     if (s[0]=='-')
  15.     {
  16.      o = true;
  17.      i++;
  18.     }
  19.     if (s[0]=='\0' || s[0]=='\n') return 0;
  20.     while (s[i]!='\0'&& s[i]!='\n')
  21.     {
  22.         if (s[i]>='0' && s[i]<='9') sm = sm*10+(s[i]-'0');
  23.         else return err;
  24.         if (sm>=max/100) return err;
  25.         i++;
  26.     }
  27.     if (o==true) return -1*sm;
  28.     else return sm;
  29. }
  30. int main ()
  31. {
  32.     FILE* fp = fopen ("tarif.txt","r");
  33.     if (fp!=NULL) printf ("Succesfully loaded tariffs\n");
  34.     else
  35.     {
  36.         printf ("error while loading tariffs\n");        
  37.         return 0;
  38.     }
  39.     int n,m,i,j;
  40.     fscanf (fp,"%d%d",&n,&m);
  41.     double a[20][12],b[20];
  42.     char name[20][100];
  43.     user u;
  44.     for (i = 0;i<n;i++)
  45.     {
  46.     for (j = 0;j<m;j++)
  47.     fscanf (fp,"%lf",&a[i][j]);
  48.     fscanf (fp,"%s",name[i]);
  49.     //fgets (name[i],100,fp);
  50.     }
  51.     fclose (fp);
  52.     int o,f=false;
  53.     char s[100];
  54.     while (true)
  55.     {
  56.         printf ("1. Enter data about user\n");
  57.         printf ("2. Calculate optimal tariff for this user\n");
  58.         printf ("3. Information about tariffs\n");
  59.         printf ("4. Contact information of velcom company\n");
  60.         printf ("5. Exit from the program\n");
  61.         scanf ("%s",&s);
  62.         o = stod (s);
  63.         if (o==1)
  64.         {
  65.             printf ("Enter please average amount per month of:\n");
  66.             printf ("1. Internet using(MB): ");
  67.             scanf ("%s",&s);
  68.             u.inet = stod(s);
  69.             if (u.inet<0)
  70.             {
  71.                 printf ("error\n");
  72.                 continue;                    
  73.             }
  74.             printf ("2. Call time in VELCOM(Minutes): ");
  75.             scanf ("%s",&s);
  76.             u.vlc = stod(s);
  77.             if (u.vlc<0)
  78.             {
  79.                 printf ("error\n");
  80.                 continue;                    
  81.             }
  82.             printf ("3. Call time in other networks(Minutes): ");
  83.             scanf ("%s",&s);
  84.             u.oth = stod(s);
  85.             if (u.oth<0)
  86.             {
  87.                 printf ("error\n");
  88.                 continue;                    
  89.             }
  90.             printf ("4. SMS count: ");
  91.             scanf ("%s",&s);
  92.             u.sms = stod(s);
  93.             if (u.sms<0)
  94.             {
  95.                 printf ("error\n");
  96.                 continue;                    
  97.             }
  98.             printf ("5. MMS count: ");
  99.             scanf ("%s",&s);
  100.             u.mms = stod(s);
  101.             if (u.mms<0)
  102.             {
  103.                 printf ("error\n");
  104.                 continue;                    
  105.             }
  106.             printf ("6. Time of calls to other countries(Minutes): ");
  107.             scanf ("%s",&s);
  108.             u.abr = stod(s);
  109.             if (u.abr<0)
  110.             {
  111.                 printf ("error\n");
  112.                 continue;                    
  113.             }
  114.             f = true;
  115.             printf ("Succesfully changed user profile\n");
  116.         }
  117.         else
  118.         if (o==2)
  119.         {
  120.             if (f==false) printf ("There is no data about user\n");
  121.             else
  122.             {  
  123.                 for (i = 0;i<n;i++)        
  124.                 {
  125.                     b[i] = a[i][6];
  126.                     if (a[i][0]!=-1 && u.inet>a[i][0]) b[i]+=(u.inet-a[i][0])*a[i][1];
  127.                     if (a[i][4]!=-1 && u.sms>a[i][4]) b[i]+=(u.sms-a[i][4])*a[i][9];
  128.                     if (a[i][5]!=-1 && u.mms>a[i][5]) b[i]+=(u.mms-a[i][5])*a[i][10];
  129.                     if (a[i][2]!=-1 && u.vlc>a[i][2]) b[i]+=(u.vlc-a[i][2])*a[i][7];
  130.                     if (a[i][3]!=-1 && u.oth>a[i][3]) b[i]+=(u.oth-a[i][3])*a[i][8];
  131.                     b[i]+=u.abr*a[i][11];
  132.                 }
  133.                 int pz[20];
  134.                 for (i = 0;i<n;i++)
  135.                 pz[i] = i;
  136.                 for (i = 0;i<n;i++)
  137.                 for (j = i+1;j<n;j++)
  138.                 if (b[pz[i]]<b[pz[j]])
  139.                 {
  140.                     int x = pz[i];
  141.                     pz[i] = pz[j];
  142.                     pz[j] = x;
  143.                 }
  144.                 for (i = 0;i<n;i++)
  145.                 printf ("tariff %s will cost %lf rubles\n\n",name[pz[i]],b[pz[i]]);
  146.             }
  147.         }
  148.         else
  149.         if (o==3)
  150.         {
  151.             for (i = 0;i<n;i++)
  152.             {
  153.                 printf ("************\n%d. Tariff name: %s\n",i,name[i]);
  154.                 if (a[i][0]==-1) printf ("Unlimited internet\n");
  155.                 else printf ("Internet(MB): %lf\n",a[i][0]);  
  156.                 printf ("Cost of 1 over used MB: %lf\n",a[i][1]);
  157.                 if (a[i][2]==-1) printf ("Unlimited minutes within Velcome\n");
  158.                 else printf ("Minutes within velcome: %lf\n",a[i][2]);
  159.                 if (a[i][3]==-1) printf ("Unlimited minutes to other networks\n");
  160.                 else printf ("Minutes to other networks: %lf\n",a[i][3]);
  161.                 if (a[i][4]==-1) printf ("Unlimited SMS\n");
  162.                 else printf ("SMS count: %lf\n",a[i][4]);
  163.                 if (a[i][5]==-1) printf ("Unlimited MMS\n");
  164.                 else printf ("MMS count: %lf\n",a[i][5]);
  165.                 printf ("Subscription fee: %lf\n",a[i][6]);
  166.                 printf ("Cost of 1 over used minut within Velcome: %lf\n",a[i][7]);
  167.                 printf ("Cost of 1 over used minut to other networks: %lf\n",a[i][8]);
  168.                 printf ("Cost of 1 over used SMS: %lf\n",a[i][9]);
  169.                 printf ("Cost of 1 over used MMS: %lf\n",a[i][10]);
  170.                 printf ("Cost of 1 call minut to other country: %lf\n",a[i][11]);
  171.             }
  172.  
  173.             printf ("\n^        ^        ^        ^        ^\n");
  174.             printf ("|        |        |        |        |\n");
  175.             printf ("Information about all Velcome tariffs\n");
  176.         }
  177.         else
  178.         if (o==4)
  179.         {
  180.             printf ("tariffs: https://www.a1.by/ru/plans/c/b2ctariffs\n");
  181.             printf ("150 - number of contact center(for free in Belarus)\n");
  182.             printf ("7100 (0.03 ruble)\n");
  183.             printf ("+375 29 6 000 150 (cost depend from roaming)\n");
  184.             printf ("email adress 150@A1.by\n");
  185.             printf ("more contact information: https://www.a1.by/ru/company/mobile-services-contacts\n");
  186.             printf ("web site: http://www.velcom.by/\n");
  187.         }
  188.         else
  189.         if (o==5) break;
  190.         else
  191.         printf ("Wrong operation\n");
  192.     printf ("\n------------------\n");
  193.     }
  194.     printf ("Do novyh vstrech");
  195.     return 0;
  196. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement