Список вопросов
Как зайти в Даркнет?!
25th January, 01:11
4
0
Как в tkinter из поля ввода Entry получить значение в одну переменную и обновить строку кнопкой, затем получить ещё одно введённое значение и затем сложить их. Ниже пример кода
21st July, 19:00
891
0
Программа, которая создает фейковые сервера в поиске игровых серверов CS 1.6 Steam
21st March, 17:43
946
0
Очень долго работает Update запрос Oracle
27th January, 09:58
912
0
не могу запустить сервер на tomcat HTTP Status 404 – Not Found
21st January, 18:02
905
0
Где можно найти фрилансера для выполнения поступающих задач, на постоянной основе?
2nd December, 09:48
936
0
Разработка мобильной кроссплатформенной военной игры
16th July, 17:57
1723
0
период по дням
25th October, 10:44
3954
0
Пишу скрипты для BAS только на запросах
16th September, 02:42
3720
0
Некорректный скрипт для закрытия блока
14th April, 18:33
4613
0
прокидывать exception в блоках try-catch JAVA
11th March, 21:11
4380
0
Помогите пожалуйста решить задачи
24th November, 23:53
6084
0
Не понимаю почему не открывается детальное описание продукта
11th November, 11:51
4350
0
Нужно решить задачу по программированию на массивы
27th October, 18:01
4394
0
Метода Крамера С++
23rd October, 11:55
4308
0
помогите решить задачу на C++
22nd October, 17:31
4002
0
Помогите решить задачу на python с codeforces
22nd October, 11:11
4492
0
Python с нуля: полное руководство для начинающих
18th June, 13:58
2598
0
Решение задачи Системы счисления с Меньшиков
Без пояснения   Просмотров: 1947
Дано целое неотрицательное число в I-ричной системе счисления. Вывести это число в J-ричной системе счисления.
Код
#include #include #include #include #include using namespace std; const int max_size = 6000; int osn = 100; struct BigInt { int digits[max_size]; int amount; BigInt() { memset(digits,0,sizeof(digits)); amount = 1; } BigInt(int dig) { memset(digits,0,sizeof(digits)); amount = 1; digits[0] = dig; } }; bool isZero(const BigInt &a) { return a.amount == 1 && a.digits[0] == 0; } BigInt operator + (const BigInt &a, const int n) { BigInt res = a; int pos = 0; res.digits[pos] += n; while (res.digits[pos]>=osn) { res.digits[pos+1]++; res.digits[pos++] -= osn; } if (res.digits[res.amount]) res.amount++; return res; } BigInt operator * (const int n, const BigInt &a) { BigInt res; res.amount = a.amount; int r = 0; for (int i=0;i =0;i--) { int cur = ost * osn + a.digits[i]; res.digits[i] = cur / n; ost = cur - res.digits[i] * n; } int pos = res.amount; while (pos !=0 && res.digits[pos] == 0) pos--; res.amount = pos+1; return res; } int operator % (const BigInt &a, const int n) { BigInt res; int ost = 0; for (int i=a.amount-1;i>=0;i--) { int cur = ost * osn + a.digits[i]; res.digits[i] = cur / n; ost = cur - res.digits[i] * n; } return ost; } string num; int ii,jj; void input() { cin>>ii>>jj; cin>>num; } void output(const vector &mas) { if (mas.size() == 0) cout<<0; else { for (int i=mas.size()-1;i>=0;i--) { if (mas[i] < 10) printf("%d", mas[i]); else printf("%c", 'A' + mas[i] - 10); } } } void solve() { // перевод в 10-ую систему BigInt dec(0); for (int i=0; i = 'A'? num[i] - 'A' + 10 : num[i] - '0'; dec = ii * dec + dig; } //перевод в jj-ую систему счисления vector res; while (!isZero(dec)) { res.push_back(dec % jj); dec = dec / jj; } output(res); } int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); input(); solve(); return 0; }
 
 
 
 
 
Автор: Администратор
Автор: Администратор
Комментарии
info@mycod.net  
Карта сайта  
Правообладателям
Заявка на расчет
×
или напишите нам прямо сейчас: