Advertisement
sellmmaahh

OR-skripta Adijata-zad 4-izbaci sve vece od k

Aug 27th, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int obrni (int n) {
  5.     int nb=0;
  6.     while (n!=0) {
  7.     nb=nb*10+n%10;
  8.     n/=10;
  9.     }
  10.     return nb;
  11. }
  12. int duzina(char *s) {
  13.     int duz=0,i=0;
  14.     while (s[i++]!='\0') duz++;
  15.     return duz;
  16. }
  17. int JeLiBroj (char c)
  18. {
  19.     if (c>='0' && c<='9') return 1;
  20.     return 0;
  21. }
  22.  
  23. void cut(char *string, int indeks, int len)
  24. {
  25.     int i;
  26.  
  27.     for(i = indeks; i <= duzina(string) - len; i++)
  28.     {
  29.         string[i] = string[i + len];
  30.     }
  31.  
  32. }
  33.  
  34. void Izbaci (char *s, int n) {
  35.     int nb=0,i,poc, kraj;
  36.     int len=duzina(s);
  37.          if (n>0) {
  38.             for (i=0; i<len; i++) {
  39.             if (JeLiBroj(s[i])) {
  40.                     poc=i;
  41.             nb=nb*10+(s[i]-'0');
  42.              i++;
  43.              while (JeLiBroj(s[i])) {
  44.                     nb=nb*10+(s[i]-'0');
  45.                     i++;
  46.              }
  47.              kraj=i;
  48.              if (nb>n) {
  49.                     cut(s, poc, kraj-poc);
  50.                     i-=(kraj-poc);
  51.              }
  52.               nb=0;
  53.             }}}
  54.  
  55.  
  56.  
  57.  
  58.     else {
  59.             n*=-1;
  60.                for (i=0; i<len; i++) {
  61.                     if(s[i]=='-' && JeLiBroj(s[i+1])) {
  62.                             i++;
  63.                             poc=i;
  64.                     nb=nb*10+(s[i]-'0');
  65.                     i++;
  66.                     while (JeLiBroj(s[i])) {
  67.                             nb=nb*10+s[i]-'0';
  68.                     i++; }
  69.                     kraj=i;
  70.  
  71.                     if (nb<n) {
  72.                             cut (s,poc-1,kraj-poc+1);
  73.                             i-=(kraj-poc+1);
  74.                               }
  75.  
  76.                                nb=0;
  77.  
  78.                     }
  79.  
  80.                     }}
  81.     }
  82.  
  83.  
  84. int main () {
  85.     char rec[]="U gradovima -68 i 910 -22 temperatura je bila -1 stepena";
  86.     Izbaci(rec,-23);
  87.     printf("\nNova recenica: %s", rec);
  88.     return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement