Форум программистов, компьютерный форум CyberForum.ru

Перестановка слов - C++

Восстановить пароль Регистрация
Другие темы раздела
C++ Считать текст из файла, и вывести только предложения, в которых нет запятой http://www.cyberforum.ru/cpp-beginners/thread353626.html
Написать програму которая считывает текст из файла и выводит на екран только предложения в которых нету запятой? Это надо сделать через роботу с файлами.
C++ Написать програму которая считывает из текстового файла три предложения Написать програму которая считывает из текстового файла три предложения и выводит их в обратном порядке. Официальным языком форума является русский язык. Называйте темы осмысленно. http://www.cyberforum.ru/cpp-beginners/thread353621.html
C++ Вывести из файла все слова, которые начинаются на гласную букву
Вивести из файла все слова котрые начинаются на гласную букву. Слова записаны на английском. ООООЧень нужна помощь!
C++ Разбить ip адрес на составляющие.
Задача такова получаем на входе строку типа string в которой содержится адрес вида "172.16.11.163" нужно получить четыре масива char по 3 элемента содержащие в себе числа адреса. например: string addr="172.16.11.163"; - на входе // что-то делаем char addrn - на выходе *addrn=172 *addrn=016 *addrn=011 *addrn=163
C++ Заполнение двумерного массива из файла. http://www.cyberforum.ru/cpp-beginners/thread353589.html
Всем привет! Застопорился на следующем. Есть некий файл следующего содержания аа аb fg df df rt ty
C++ Задача на цикл, ошибка кода Помогите найти ошибку в коде, программа не компилируется... вот задание: Дано натуральное число n. Выяснить, можно ли представить n! в виде произведения трех последовательных целых чисел. #include <iosteam.h> int fact(int N) //Расчет факториала N { int result=1; for (int i=2; i<=N; i++) подробнее

Показать сообщение отдельно
-=ЮрА=-
Заблокирован
Автор FAQ
19.09.2011, 14:06     Перестановка слов
Вот накидал на Си, недостатки scanf-а попытался убрать посредством разбиения текста на токены
C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdlib.h> //malloc
#include <string.h> //strlen strtok
#include <stdio.h>  //i/o
 
int main()
{
    long sLen;
    char * str, *buf;
    char swap[256];
    char delim[] = " ,.!?\n";
    FILE * f = fopen("text.txt","rb+");
    if(!f)
        printf("Error open text.txt\r\n");
    else
    {
        fseek(f,0,SEEK_END);
        sLen = ftell(f);
        fseek(f,0,SEEK_SET);
        if(!(str = (char *)malloc(sLen + 1)))
            printf("allocation memory error\r\n");
        else
        {
            fread(str,sLen,1,f);
            str[sLen] = '\0';
        }
        fclose(f);
        if(str)
        {
            if(!strstr(str," "))
                printf("File consist from one word\r\n");
            else
            {
                buf = strtok(str,delim);
                while(buf)
                {
                    strncpy(swap,buf,(sLen = strlen(buf)));
                    swap[sLen] = '\0';
                    if(buf = strtok(NULL,delim))
                        printf("%s %s ",buf,swap);
                    else
                        printf("%s ",swap);
                }
            }
        }
    }
    printf("\r\nEnter any key\r\n");
    char ch;scanf("%c",&ch);
    return 0;
}
[Результат работы]

вывод консоли
collapse Gravitational is collapse the is inward the fall inward of fall a of bo
dy a due body to due the to influence the of influence its of own its gravity ow
n In gravity any In stable any body stable this body gravitational this force gr
avitational is force counterbalanced is by counterbalanced the by internal the p
ressure internal of pressure the of body the in body the in opposite the directi
on opposite to direction the to force the of force gravity of (gravity gravity b
eing (gravity generally being orientated generally to orientated the to center t
he of center mass) of If mass) the If inwards the pointing inwards gravitational
pointing force gravitational however force is however stronger is than stronger
the than total the combination total of combination the of outward the pointing
outward forces pointing the forces equilibrium the becomes equilibrium unbalanc
ed becomes and unbalanced a and collapse a occurs collapse until occurs the unti
l internal the pressure internal increases pressure above increases that above o
f that the of gravitational the force gravitational and force a and equilibrium
a is equilibrium once is again once attained again (the attained exception (the
gravity Because is gravity comparatively is weak comparatively compared weak to
compared other to fundamental other forces fundamental gravitational forces col
lapse gravitational is collapse usually is associated usually with associated ve
ry with massive very bodies massive or bodies collections or of collections bodi
es of such bodies as such stars as (including stars collapsed (including stars c
ollapsed such stars as such supernovae as neutron supernovae stars neutron and s
tars black and holes) black and holes) massive and collections massive of collec
tions stars of such stars as such globular as clusters globular and clusters gal
collapse Gravitational is collapse at is the at heart the of heart structure of
formation structure in formation the in universe the An universe initial An smo
oth initial distribution smooth of distribution matter of will matter eventually
will collapse eventually and collapse cause and a cause hierarchy a of hierarch
y structures of such structures as such clusters as of clusters galaxies of stel
lar galaxies groups stellar stars groups and stars planets and For planets examp
le For a example star a is star born is through born the through gradual the gra
vitational gradual collapse gravitational of collapse a of cloud a of cloud inte
rstellar of matter interstellar The matter compression The caused compression by
caused the by collapse the raises collapse the raises temperature the until tem
perature nuclear until fuel nuclear reignites fuel in reignites the in center th
e of center the of star the and star the and collapse the comes collapse to come
s a to halt a The halt thermal The pressure thermal gradient pressure (leading g
radient to (leading expansion) to compensates expansion) the compensates gravity
the (leading gravity to (leading compression) to and compression) a and star a
is star in is dynamical in equilibrium dynamical between equilibrium these betwe
collapse Gravitational of collapse a of star a occurs star at occurs the at end
the of end its of lifetime its also lifetime called also the called death the o
f death the of star the When star all When stellar all energy stellar sources en
ergy are sources exhausted are the exhausted star the will star undergo will a u
ndergo gravitational a collapse gravitational In collapse this In sense this a s
ense star a is star in is a in "temporary" a equilibrium "temporary" state equil
ibrium between state a between gravitational a collapse gravitational at collaps
e stellar at birth stellar and birth a and further a gravitational further colla
pse gravitational at collapse stellar at death stellar The death end The states
dwarfs White in dwarfs which in gravity which is gravity opposed is by opposed
stars Neutron in stars which in gravity which is gravity opposed is by opposed
neutron by degeneracy neutron pressure degeneracy and pressure short-range and r
epulsive short-range neutron-neutron repulsive interactions neutron-neutron medi
holes Black in holes which in the which physics the at physics the at center th
collapse The to collapse a to white a dwarf white takes dwarf place takes over
place tens over of tens thousands of of thousands years of while years the while
star the blows star off blows its off outer its envelope outer to envelope form
to a form planetary a nebula planetary If nebula it If has it a has companion a
star companion a star white a dwarf-sized white object dwarf-sized can object a
ccrete can matter accrete from matter a from companion a star companion until st
ar it until reaches it the reaches Chandrasekhar the limit Chandrasekhar at limi
t which at point which gravitational point collapse gravitational takes collapse
over takes again over While again it While might it seem might that seem the th
at white the dwarf white might dwarf collapse might to collapse the to next the
stage next (neutron stage star) (neutron they star) instead they undergo instead
runaway undergo carbon runaway fusion carbon blowing fusion completely blowing
apart completely in apart a in Type a Ia Type supernova Ia Neutron supernova sta
rs Neutron are stars formed are by formed gravitational by collapse gravitationa
l of collapse larger of stars larger the stars remnant the of remnant other of t
more Even massive more stars massive above stars the above Tolman-Oppenheimer-V
olkoff the limit Tolman-Oppenheimer-Volkoff cannot limit find cannot a find new
a dynamical new equilibrium dynamical with equilibrium any with known any force
known opposing force gravity opposing Hence gravity the Hence collapse the conti
nues collapse with continues nothing with to nothing stop to it stop Once it it
Once collapses it to collapses within to its within Schwarzschild its radius Sch
warzschild not radius even not light even can light escape can from escape the f
rom star the and star hence and it hence becomes it a becomes black a hole black
According hole to According theories to at theories some at point some later po
int the later collapsing the object collapsing will object reach will the reach
maximum the possible maximum energy possible density energy for density a for ce
rtain a volume certain of volume space of or space the or Planck the density Pla
nck (as density there (as is there nothing is that nothing can that stop can it)
stop where it) the where known the laws known of laws gravity of cease gravity
to cease be to valid be [1] valid There [1] are There competing are theories com
peting as theories to as what to occurs what at occurs this at point this but po
int it but can it no can longer no really longer be really considered be gravita
might It be might thought be that thought a that sufficiently a large sufficien
tly neutron large star neutron could star exist could inside exist its inside Sc
hwarzschild its radius Schwarzschild and radius appear and like appear a like bl
ack a hole black without hole having without all having the all mass the compres
sed mass to compressed a to singularity a at singularity the at center; the howe
ver center; this however is this a is misconception a Within misconception the W
ithin event the horizon event matter horizon would matter have would to have mov
e to outwards move faster outwards than faster the than speed the of speed light
of in light order in to order remain to stable remain and stable avoid and coll
apsing avoid to collapsing the to center the No center physical No force physica
l can force therefore can prevent therefore the prevent star the from star colla
psing from to collapsing a to singularity a (at singularity least (at within lea
st the within currently the understood currently framework understood of framewo
rk general of relativity) general A relativity) model A for model nonspherical f
or collapse nonspherical in collapse general in relativity general with relativi
ty emission with of emission matter of and matter gravitational and waves gravit
ational was waves presented was in presented [2] in [2]
Enter any key


Файл данных
text.txt
Gravitational collapse is the inward fall of a body due to the influence of its own gravity. In any stable body, this gravitational force is counterbalanced by the internal pressure of the body, in the opposite direction to the force of gravity (gravity being generally orientated to the center of mass). If the inwards pointing gravitational force, however, is stronger than the total combination of the outward pointing forces, the equilibrium becomes unbalanced and a collapse occurs until the internal pressure increases above that of the gravitational force and a equilibrium is once again attained (the exception being black holes).
Because gravity is comparatively weak compared to other fundamental forces, gravitational collapse is usually associated with very massive bodies or collections of bodies, such as stars (including collapsed stars such as supernovae, neutron stars and black holes) and massive collections of stars such as globular clusters and galaxies.
Gravitational collapse is at the heart of structure formation in the universe. An initial smooth distribution of matter will eventually collapse and cause a hierarchy of structures, such as clusters of galaxies, stellar groups, stars and planets. For example, a star is born through the gradual gravitational collapse of a cloud of interstellar matter. The compression caused by the collapse raises the temperature until nuclear fuel reignites in the center of the star and the collapse comes to a halt. The thermal pressure gradient (leading to expansion) compensates the gravity (leading to compression) and a star is in dynamical equilibrium between these two forces.
Gravitational collapse of a star occurs at the end of its lifetime, also called the death of the star. When all stellar energy sources are exhausted, the star will undergo a gravitational collapse. In this sense a star is in a "temporary" equilibrium state between a gravitational collapse at stellar birth and a further gravitational collapse at stellar death. The end states are called compact stars.
The types of compact stars are:
White dwarfs, in which gravity is opposed by electron degeneracy pressure;
Neutron stars, in which gravity is opposed by neutron degeneracy pressure and short-range repulsive neutron-neutron interactions mediated by the strong force;
Black holes, in which the physics at the center is unknown.
The collapse to a white dwarf takes place over tens of thousands of years, while the star blows off its outer envelope to form a planetary nebula. If it has a companion star, a white dwarf-sized object can accrete matter from a companion star until it reaches the Chandrasekhar limit, at which point gravitational collapse takes over again. While it might seem that the white dwarf might collapse to the next stage (neutron star), they instead undergo runaway carbon fusion, blowing completely apart in a Type Ia supernova. Neutron stars are formed by gravitational collapse of larger stars, the remnant of other types of supernova.
Even more massive stars, above the Tolman-Oppenheimer-Volkoff limit cannot find a new dynamical equilibrium with any known force opposing gravity. Hence, the collapse continues with nothing to stop it. Once it collapses to within its Schwarzschild radius, not even light can escape from the star, and hence it becomes a black hole. According to theories, at some point later the collapsing object will reach the maximum possible energy density for a certain volume of space or the Planck density (as there is nothing that can stop it), where the known laws of gravity cease to be valid.[1] There are competing theories as to what occurs at this point, but it can no longer really be considered gravitational collapse at that stage.
It might be thought that a sufficiently large neutron star could exist inside its Schwarzschild radius and appear like a black hole without having all the mass compressed to a singularity at the center; however, this is a misconception. Within the event horizon, matter would have to move outwards faster than the speed of light in order to remain stable and avoid collapsing to the center. No physical force can therefore prevent the star from collapsing to a singularity (at least within the currently understood framework of general relativity). A model for nonspherical collapse in general relativity with emission of matter and gravitational waves was presented in [2].
 
Текущее время: 18:10. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2016, vBulletin Solutions, Inc.
Рейтинг@Mail.ru