Vladislav_Bezruk

Some task

Oct 30th, 2020 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int i,j;
  4. char a;
  5. bool o;
  6. int ip = 1;
  7. int num[15],gnum[15];
  8. int numl,nnum,npoint;
  9. bool number , point , k;
  10. int s;
  11.  
  12. int main() {
  13.    
  14.     number = false;
  15.     point = true;
  16.    
  17.     for (i = 1 ; i <= 15 ; i++) {
  18.    
  19.     if (numl > 0) {
  20.        
  21.     for (j = 0 ; j < numl ; j++) {
  22.     gnum[j] = num[numl-(j+1)]; 
  23.     }
  24.    
  25.     s = gnum[0] + 10 * gnum[1] + 100 * gnum[2] + 1000 * gnum[3];
  26.  
  27.     if (s > 255) {
  28.     break;
  29.     ip = 0;    
  30.     }
  31.        
  32.     }
  33.        
  34.     k = false;
  35.    
  36.     scanf("%c",&a);
  37.    
  38.     if (a == '.'){     
  39.     if (point == false) {
  40.     npoint += 1;   
  41.     }
  42.     number = false;
  43.     point = true;
  44.     o = false; 
  45.     numl = 0;  
  46.     }
  47.     else {
  48.     switch (a) {
  49.         case '0':k = true;
  50.         case '1':k = true;
  51.         case '2':k = true;
  52.         case '3':k = true;
  53.         case '4':k = true;
  54.         case '5':k = true;
  55.         case '6':k = true;
  56.         case '7':k = true;
  57.         case '8':k = true;
  58.         case '9':k = true; 
  59.     }
  60.    
  61.     if (k == false) {
  62.     break;
  63.     if (not (nnum == 4 and npoint == 3))
  64.     ip = 0;    
  65.     }
  66.     }
  67.    
  68.     if (k == true)     
  69.     if (number == false and point == true)  {
  70.     nnum += 1;
  71.     number = true;
  72.     if (a != '0') {
  73.     o = true;
  74.     numl += 1;     
  75.     num[numl-1] = a-'0';
  76.     }
  77.     point = false; 
  78.     }
  79.     else {
  80.     point = false; 
  81.    
  82.     if (o == false and a != '0' or o == true) {
  83.     o = true;  
  84.     numl += 1;
  85.     num[numl-1] = a-'0';   
  86.     }
  87.            
  88.     }
  89.        
  90.     }
  91.        
  92.     if (not (nnum == 4 and npoint == 3))
  93.     ip = 0;
  94.    
  95.     printf("%i",ip);
  96.    
  97.     return 0;
  98. }
Add Comment
Please, Sign In to add comment