|
Banned
Регистрация: 24.12.2009
Сообщений: 141
С нами:
8622379
Репутация:
45
|
|
2 xanser
1-я (пишу без лабуды) (бью прямо тут без проверки)
Код:
int i,j,fl;
char str[]="jhb sdjcnweofnlm wefoi-pokas lknlqkmwdqw";
for(i=0;*(str+i)!=0;i++)
{
for(j=0,fl=0;*(str+j)!=0 && fl==0;j++)
if(*(str+i)==*(str+j) && i!=j)
fl=0;
if(fl==0)
printf("%c",*(str+i));
}
правильно ли я понял что компонентами называются лексемы разделенные пробелом запятой точкой вопросительным и восклицательным знаками а так же переводом строки?
если ДА , то
2-я (пишу без лабуды) (бью прямо тут без проверки)
P.S. проверка на простое по Кнут-у
Код:
int havegotfield(char *sourcestr,char *deststr,int nelement,char *delimiterStr,int mode)
{
int i;
int mcnt;
char tstr[300];
int flrez=0;
int pstr=0;
int prepfl;
*(deststr)=0;
if(strchr(delimiterStr,*(sourcestr))!=0)
prepfl=0;
else
prepfl=1;
for(i=0,mcnt=1,flrez=0,prepfl=0;*(sourcestr+i)!=0;i++)
{
if(strchr(delimiterStr,*(sourcestr+i))!=NULL)
{
if(mode==0)
{
if(prepfl!=0)
{
if(mcnt<=nelement)
mcnt++;
else
break;
}
prepfl=0;
}
else
{
if(mcnt<=nelement)
mcnt++;
else
{
flrez=1;
break;
}
}
}
else
{
if(mcnt==nelement)
{
*(deststr+pstr)=*(sourcestr+i);
pstr++;
flrez=1;
}
prepfl=1;
}
}
*(deststr+pstr)=0;
return flrez;
}
unsigned long numb;
int simpl[10]={2,3,5,7,11,13,17,19,23,29};
long test_simple(unsigned long num)
{
int i;
unsigned long p,j;
long rez;
if(num<100)
{
for(i=0;i<10;i++)
if((numb/simpl[i])*simpl[i]==numb && numb!=simpl[i])
return -2;
for(i=0;i<10;i++)
if((num/simpl[i])*simpl[i]==num && num!=simpl[i])
return -1;
return num;
}
else
{
p=sqrt(num);
for(j=0;j<p-sqrt(p);j++)
{
rez=test_simple(p-j);
if(rez!=-1)
{
if(rez==-2)
return -2;
if((numb/rez)*rez==numb)
{
return -1;
}
}
}
return num;
}
}
int main()
{
char str[1500],buf[10],dstr[100];
int ind=0;
int kolvo=0;
int i,j,k;
unsigned long n;
CFile f;
CFileException e;
char path[300];
printf("\r\nInput file path:");
scanf("%s",path);
if(f.Open(path,CFile::modeRead,&e))
{
while(f.Read(buf,1)==1)
{
switch(*buf)
{
case 0x0d:
*(str+ind)=0;
break;
case 0x0a:
for(i=1;havegotfield(str,dstr,i," .,!?-+",1)!=0;i++)
{
n=strtoul(str,0,10);
n=numb=sqrt(n);
l=test_simple(n);
if(!(l==-1 || l==-2))
printf("\r\n-%s-",dstr); \\ вывод но можно и посчитать типа kolvo++;
\\
}
ind=0;
default:
*(str+ind)=*(buf);
ind++;
}
}
f.Close();
}
}
Последний раз редактировалось Retimiled; 28.12.2009 в 19:18..
|