Помощь - Поиск - Пользователи - Календарь
Полная версия: Работа со строками (слова и чтение чисел из строки
Форум «Всё о Паскале» > Delphi, Assembler и другие языки. > Другие языки
Altair

#include <stdio.h> 
#include <ctype.h>
#include <math.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>

int summ (char *s1)
{
  char*p;
  int first = 0, T;

  p = s1;
  do {
    while( *p && !(isdigit(*p)) ) ++p;
    sscanf(p, "%d", &T); first += T;
    while(isdigit(*p)) ++p;
  } while(*p);

	return first;
}

int max (char *s2)
{
	char*p;
	int T,tekmax=0;
	p = s2;
	do {
       while( *p && !(isdigit(*p)) ) ++p;
       sscanf(p, "%d", &T); 
    if (T > tekmax) {tekmax=T;}
    while(isdigit(*p)) ++p;
    } while(*p);
	return tekmax;
}  


int main () 
{
  int n;
  do {  
	printf ("Enter N\n");	
	scanf ("%d",&n);
    if (n>80)   {printf("error");}	
  }	
  while (n>80);      
  char *s1, *s2;
  s1=(char*)malloc(n*sizeof(char));  
  s2=(char*)malloc(n*sizeof(char));
  fflush(stdin);
  printf("enter string 1\n");  gets (s1);
  printf("enter string 2\n");  gets (s2);
  if (max(s2)>summ(s1)) {
   printf("Found!");
  }
   else
   {
     printf("NOT FOUND!!!");
  }  
    return 0;	
}
volvo
cool.gif

#include <stdio.h>
#include <stdlib.h>
#include <alloc.h>
#include <ctype.h>

int main() {

  int n, T, first = 0, second = 0;
  char *str1, *str2, *p;

  printf("enter the max length:");
  scanf("%d", &n);
  if(
      ((str1 = (char *)malloc(n + 1)) == NULL) ||
      ((str2 = (char *)malloc(n + 1)) == NULL)
    )
  {
    printf("cannot allocate memory"); exit(-1);
  }

  fflush(stdin);
  printf("string 1: "); gets(str1);
  printf("string 2: "); gets(str2);

  p = str1;
  do {
    while( *p && !(isdigit(*p)) ) ++p;
    sscanf(p, "%d", &T); first += T;
    while(isdigit(*p)) ++p;
  } while(*p);

  p = str2;
  do {
    while( *p && !(isdigit(*p)) ) ++p;
    sscanf(p, "%d", &T); second = max(second, T);
    while(isdigit(*p)) ++p;
  } while(*p);

  if(second > first) printf("yes");
  else printf("no");

  free(str2);
  free(str1);

  return 0;

}
volvo
blum.gif Утечка памяти у Вас, уважаемый lol.gif
Это текстовая версия — только основной контент. Для просмотра полной версии этой страницы, пожалуйста, нажмите сюда.