Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- using namespace std;
- struct MyStruct
- {
- string liczba_przed_kropka;
- string liczba_po_kropce;
- string symbol;
- int dlugosc_po_kropce;
- };
- MyStruct str;
- void PodzielSymbol(string symbol) {
- int dlugosc;
- dlugosc = symbol.length();
- bool czy_jest_kropka = false;
- int pozycja_kropki = 1;
- int dlugosc_symbolu = 0;
- string znak;
- //Pobierz symbol
- if (isupper(symbol[dlugosc - 2])) {
- znak = symbol[dlugosc - 2];
- znak += symbol[dlugosc - 1];
- dlugosc_symbolu = 2;
- }
- else {
- znak = symbol[dlugosc - 1];
- dlugosc_symbolu = 1;
- }
- str.symbol = znak;
- //sprawdz czy w wyrazeniu istnieje kropka i pobierz jej miejsce
- for (int i = 0; i < dlugosc; i++) {
- if (symbol[i] == '.') {
- czy_jest_kropka = true;
- break;
- }
- pozycja_kropki++;
- }
- //Pobierz wartość przed kropka jesli istnieje. Jeżeli nie pobierz cała wartość bez symbolu
- if (czy_jest_kropka == true) {
- for (int i = 0; i < pozycja_kropki - 1; i++) {
- str.liczba_przed_kropka += symbol[i];
- }
- }
- else {
- for (int i = 0; i < dlugosc - dlugosc_symbolu; i++) {
- str.liczba_przed_kropka += symbol[i];
- }
- }
- cout << str.liczba_po_kropce;
- //Pobierz wartość po kropce jesli istnieje bez symbolu
- if (czy_jest_kropka == true) {
- str.dlugosc_po_kropce += dlugosc - dlugosc_symbolu - pozycja_kropki;
- for (int i = pozycja_kropki; i < dlugosc - dlugosc_symbolu; i++)
- {
- str.liczba_po_kropce += symbol[i];
- }
- }
- }
- void WypiszWyik(int liczba_zer) {
- string wynik;
- wynik += str.liczba_przed_kropka;
- if (str.dlugosc_po_kropce == 0) {
- for (int i = 0; i < liczba_zer; i++)
- {
- wynik += "0";
- }
- }
- else {
- wynik += str.liczba_po_kropce;
- for (int i = 0; i < liczba_zer - str.dlugosc_po_kropce; i++)
- {
- wynik += "0";
- }
- }
- cout << wynik << endl;
- }
- void Konwertuj(string symbol) {
- PodzielSymbol(symbol);
- if (str.symbol == "M") {
- WypiszWyik(6);
- cout << endl;
- }
- else if (str.symbol == "B") {
- WypiszWyik(9);
- cout << endl;
- }
- else if (str.symbol == "T") {
- WypiszWyik(12);
- cout << endl;
- }
- else if (str.symbol == "Qa") {
- WypiszWyik(15);
- cout << endl;
- }
- else if (str.symbol == "Qi") {
- WypiszWyik(18);
- cout << endl;
- }
- else if (str.symbol == "Sx") {
- WypiszWyik(21);
- cout << endl;
- }
- else if (str.symbol == "Sp") {
- WypiszWyik(24);
- cout << endl;
- }
- else if (str.symbol == "Oc") {
- WypiszWyik(27);
- cout << endl;
- }
- }
- int main()
- {
- Konwertuj("999.99M");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement