powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / C++ [игнор отключен] [закрыт для гостей] / помогите мне с ошибками, пожалуйста!!!
2 сообщений из 2, страница 1 из 1
помогите мне с ошибками, пожалуйста!!!
    #38311749
druce
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
создание программу, реализующую алгоритм, преобразующий произвольное положительное число, записанное в арабских цифрах, в систему римских цифр и наоборот.

Код: plaintext
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.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
#include <iostream>
#include <string>
int get_arab_num(std::string rom_str)
using namespace std;
int main(int argc, char* argv[])

{
    int res = 0;
    for(size_t i = 0; i < rom_str.length(); ++i)
    {
        switch(rom_str[i])
        {
        case 'M': 
            res += 1000;
            break;
        case 'D': 
            res += 500;
            break;
        case 'C':
            i + 1 < rom_str.length() 
                    &&  (rom_str[i + 1] == 'D' 
                         || rom_str[i + 1] == 'M') ? res -= 100 : res += 100;            
            break;
        case 'L': 
            res += 50;
            break;
        case 'X': 
            i + 1 < rom_str.length() 
                    &&  (rom_str[i + 1] == 'L' 
                         || rom_str[i + 1] == 'C') ? res -= 10 : res += 10;            
            break;
        case 'V': 
            res += 5;
            break;
        case 'I': 
            i + 1 < rom_str.length() 
                    &&  (rom_str[i + 1] == 'V' 
                         || rom_str[i + 1] == 'X') ? res -= 1 : res += 1;            
            break;
 
        }//switch
    }//for
    return res;
}
 
int main()
{
    std::string s;
    for(;;)
    {
        std::cout << "input roman num: ";
        std::cin >> s;
        std::cout 
            << "arab num = "
            << get_arab_num(s)
            << std::endl
            << std::endl;
    }
    return 0;
}
{
    const int M = 1000;
    const int D = 500;
    const int C = 100;
    const int L = 50;
    const int X = 10;
    const int V = 5;
    const int I = 1;
    int nNum;
    cout<<"Input number: ";
    cin>>nNum;
    int nM = nNum/M;
    int nRemainM = nNum%M;
    int nD = nRemainM/D;
    int nRemainD = nRemainM%D;
    int nC = nRemainD/C;
    int nRemainC = nRemainD%C;
    int nL = nRemainC/L;
    int nRemainL = nRemainC%L;
    int nX = nRemainL/X;
    int nRemainX = nRemainL%X;
    int nV = nRemainX/V;
    int nRemainV = nRemainX%V;
    int nI = nRemainV;
    int i;
    for(i = 0; i < nM; i++)
        cout<<"M";
    for(i = 0; i < nD; i++)
        cout<<"D";
    for(i = 0; i < nC; i++)
        cout<<"C";
    for(i = 0; i < nL; i++)
        cout<<"L";
    for(i = 0; i < nX; i++)
        cout<<"X";
    for(i = 0; i < nV; i++)
        cout<<"V";
    for(i = 0; i < nI; i++)
        cout<<"I";
    cout<<"\n";
    return 0;
}
...
Рейтинг: 0 / 0
помогите мне с ошибками, пожалуйста!!!
    #38311758
druce
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
[quot druce]создание программу, реализующую алгоритм, преобразующий произвольное положительное число, записанное в арабских цифрах, в систему римских цифр и наоборот.

Код: plaintext
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.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
    const int M = 1000;
    const int D = 500;
    const int C = 100;
    const int L = 50;
    const int X = 10;
    const int V = 5;
    const int I = 1;
    int nNum;
    cout<<"Input number: ";
    cin>>nNum;
    int nM = nNum/M;
    int nRemainM = nNum%M;
    int nD = nRemainM/D;
    int nRemainD = nRemainM%D;
    int nC = nRemainD/C;
    int nRemainC = nRemainD%C;
    int nL = nRemainC/L;
    int nRemainL = nRemainC%L;
    int nX = nRemainL/X;
    int nRemainX = nRemainL%X;
    int nV = nRemainX/V;
    int nRemainV = nRemainX%V;
    int nI = nRemainV;
    int i;
    for(i = 0; i < nM; i++)
        cout<<"M";
    for(i = 0; i < nD; i++)
        cout<<"D";
    for(i = 0; i < nC; i++)
        cout<<"C";
    for(i = 0; i < nL; i++)
        cout<<"L";
    for(i = 0; i < nX; i++)
        cout<<"X";
    for(i = 0; i < nV; i++)
        cout<<"V";
    for(i = 0; i < nI; i++)
        cout<<"I";
    cout<<"\n";
    return 0;
}
int get_arab_num(std::string rom_str)
{
    int res = 0;
    for(size_t i = 0; i < rom_str.length(); ++i)
    {
        switch(rom_str[i])
        {
        case 'M': 
            res += 1000;
            break;
        case 'D': 
            res += 500;
            break;
        case 'C':
            i + 1 < rom_str.length() 
                    &&  (rom_str[i + 1] == 'D' 
                         || rom_str[i + 1] == 'M') ? res -= 100 : res += 100;            
            break;
        case 'L': 
            res += 50;
            break;
        case 'X': 
            i + 1 < rom_str.length() 
                    &&  (rom_str[i + 1] == 'L' 
                         || rom_str[i + 1] == 'C') ? res -= 10 : res += 10;            
            break;
        case 'V': 
            res += 5;
            break;
        case 'I': 
            i + 1 < rom_str.length() 
                    &&  (rom_str[i + 1] == 'V' 
                         || rom_str[i + 1] == 'X') ? res -= 1 : res += 1;            
            break;
 
        }//switch
    }//for
    return res;
}
 
int main()
{
    std::string s;
    for(;;)
    {
        std::cout << "input roman num: ";
        std::cin >> s;
        std::cout 
            << "arab num = "
            << get_arab_num(s)
            << std::endl
            << std::endl;
    }
    return 0;
}


Модератор: Отредактировано
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / C++ [игнор отключен] [закрыт для гостей] / помогите мне с ошибками, пожалуйста!!!
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]