Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 03.11.2010, 20:55   #1
jambas92
Пользователь
 
Регистрация: 09.10.2010
Сообщений: 27
По умолчанию Else if (c++)

Здравствуйте, у меня ошибка с else if ом, просьба поставить код else if правильно что бы код работал. Заранее спасибо.

#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;

int main() {

char str[1001];
char temp1[1001];
char temp2[1001];

cin.getline(str, 1000);

int n = strlen(str);

bool numbersSequence = false;
int begin, end;

for (int i=0; i<n; i++) {
if (isdigit(str[i])) {
if (!numbersSequence) {
begin = i;
numbersSequence = true;
}
end = i;
} else {
if (numbersSequence) {
strncpy(temp1, str + begin, end - begin + 1);
temp1[end - begin + 1] = '\0';
char *ptr=temp1;
int x=strlen(ptr);

for (int i=0; i<x%3; i++)
cout << *(ptr+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2) << " ";
else
cout << " " << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2);
}
}
numbersSequence = false;
}
}
else
{
if (numbersSequence) {
strncpy(temp2, str + begin, end - begin + 1);
temp2[end - begin + 1] = '\0';
char *ptr=temp2;
int x=strlen(ptr);

for (int i=0; i<x%3; i++)
cout << *(ptr+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2) << " ";
else
cout << " " << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2);
}

numbersSequence = false;
}
else
{
char *ptr1=temp1;
char *ptr2=temp2;
int x=strlen(ptr1);
int y=strlen(ptr2);

if (x==y)
{
if (temp1[0]>temp2[0])
{
for (int i=0; i<x%3; i++)
cout << *(ptr1+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2) << " ";
else
cout << " " << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2);
}
}
else
{
if (temp2[0]>temp1[0])
{
for (int i=0; i<y%3; i++)
cout << *(ptr2+i);

for (int i=y%3; i<y; i=i+3)
{
if (y%3==0)
cout << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2) << " ";
else
cout << " " << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2);
}
}
}
}
else
{
if (x>y)
{
for (int i=0; i<x%3; i++)
cout << *(ptr1+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2) << " ";
else
cout << " " << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2);
}
}
else
{
if (y>x)
{
for (int i=0; i<y%3; i++)
cout << *(ptr2+i);

for (int i=y%3; i<y; i=i+3)
{
if (y%3==0)
cout << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2) << " ";
else
cout << " " << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2);
}
}
}
}
}
}
return 0;
}
jambas92 вне форума Ответить с цитированием
Старый 03.11.2010, 21:00   #2
_-Re@l-_
C++, Java
Старожил
 
Аватар для _-Re@l-_
 
Регистрация: 10.04.2010
Сообщений: 2,665
По умолчанию

Вы хоть оформите код тегом #, читабельней будет.
_-Re@l-_ вне форума Ответить с цитированием
Старый 03.11.2010, 21:00   #3
kaljan775
:D
Форумчанин
 
Аватар для kaljan775
 
Регистрация: 26.09.2010
Сообщений: 570
По умолчанию

будьте добры, оформьте код(# на панели инструментов) и покажите месте, где вы хотите чтобы мы помогли,
Пишу ПО, создаю сайты, делаю курсовые работы, за деньги
C#, .NET, MS SQL, AngularJS, HTML, jQuery
kaljan775 вне форума Ответить с цитированием
Старый 03.11.2010, 21:11   #4
jambas92
Пользователь
 
Регистрация: 09.10.2010
Сообщений: 27
По умолчанию

ок. хорошо

#include <iostream>
#include <cstring>
#include <cctype>

using namespace std;

int main() {

char str[1001];
char temp1[1001];
char temp2[1001];

cin.getline(str, 1000);

int n = strlen(str);

bool numbersSequence = false;
int begin, end;

for (int i=0; i<n; i++) {
if (isdigit(str[i])) {
if (!numbersSequence) {
begin = i;
numbersSequence = true;
}
end = i;
} else {
if (numbersSequence) {
strncpy(temp1, str + begin, end - begin + 1);
temp1[end - begin + 1] = '\0';
char *ptr=temp1;
int x=strlen(ptr);

for (int i=0; i<x%3; i++)
cout << *(ptr+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2) << " ";
else
cout << " " << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2);
}
}
numbersSequence = false;
}
}
else // вот здесь могли бы мне помочь
{
if (numbersSequence) {
strncpy(temp2, str + begin, end - begin + 1);
temp2[end - begin + 1] = '\0';
char *ptr=temp2;
int x=strlen(ptr);

for (int i=0; i<x%3; i++)
cout << *(ptr+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2) << " ";
else
cout << " " << *(ptr+i) << *(ptr+i+1) << *(ptr+i+2);
}

numbersSequence = false;
}
else
{
char *ptr1=temp1;
char *ptr2=temp2;
int x=strlen(ptr1);
int y=strlen(ptr2);

if (x==y)
{
if (temp1[0]>temp2[0])
{
for (int i=0; i<x%3; i++)
cout << *(ptr1+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2) << " ";
else
cout << " " << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2);
}
}
else
{
if (temp2[0]>temp1[0])
{
for (int i=0; i<y%3; i++)
cout << *(ptr2+i);

for (int i=y%3; i<y; i=i+3)
{
if (y%3==0)
cout << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2) << " ";
else
cout << " " << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2);
}
}
}
}
else
{
if (x>y)
{
for (int i=0; i<x%3; i++)
cout << *(ptr1+i);

for (int i=x%3; i<x; i=i+3)
{
if (x%3==0)
cout << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2) << " ";
else
cout << " " << *(ptr1+i) << *(ptr1+i+1) << *(ptr1+i+2);
}
}
else
{
if (y>x)
{
for (int i=0; i<y%3; i++)
cout << *(ptr2+i);

for (int i=y%3; i<y; i=i+3)
{
if (y%3==0)
cout << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2) << " ";
else
cout << " " << *(ptr2+i) << *(ptr2+i+1) << *(ptr2+i+2);
}
}
}
}
}
}
return 0;
}
jambas92 вне форума Ответить с цитированием
Старый 03.11.2010, 21:13   #5
jambas92
Пользователь
 
Регистрация: 09.10.2010
Сообщений: 27
По умолчанию

строка №48
jambas92 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц