konwersja:
string l;
cin >> l;
int c = atoi(l.c_str());
lub od razu:
int c;
cin >> c;
Przy drugiej opcji może i łatwiej operować na intach, ale ciężej o długość ciągu znaków.
@Edit
Jak dzielić liczbę na części, najlepiej numerowane, czyli, mam dajmy na to 123321, chcę to podzielić na części o numerach 1(123) i 2(321). Jak takiego cudu dokonać?
@Edit2
Mam takie coś, liczy to do 999, znaczy wypisuje do 999. Teraz chcę to zapętlić zależnie od długości stringa, ale ni diabła, ni cholery, nie wiem jak, pomimo tego, że jakoś już to dzielę. Jednak wynik jest taki, że z 29999 wypisze mi 29, a jeżeli dam np. 288233, to cały program się wiesza.
Oto i kod.
Usunięto z powodu nowszej wersji
@Edit3
Stworzyłem wersję, która niby wypisuje od 0 do 999 mln, ale, kiedy przy większej liczbie dochodzi do setek, zaczynają się dziać niestworzone cuda. Oto ta wersja.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
string t[4][20]={
{"zero","jeden","dwa","trzy","cztery","piec","szesc","siedem","osiem","dziewiec","dziesiec","jedynascie","dwanascie","trzynascie","czternascie","pietnascie","szesnascie","siedemnascie","osiemnascie","dziewietnascie"},
{"zero","dwadziescia","trzydziesci","czterdziesci","piecdziesiat","szescdziesiat","siedemdziesiat","osiemdziesiat","dziewiecdziesiat"},
{"zero","sto","dwiescie","trzysta","czterysta","piecset","szescset","siedemset","osiemset","dziewiecset"},
{"zero","Tys","Mln"}
};
int main()
{
string l;
cin >> l;
int n = l.length();
int c = strtol(l.c_str(), NULL, 10);
int a = 0;
int g = n % 3;
if (n<=3)
{
if (c<=19)
cout << t[0][c];
else if (n==2 && c>=20)
{
a=(c-(10*(c/10)));
c=(c/10)-1;
if (a==0)
cout << t[1][c];
else
cout << t[1][c] << " " << t[0][a];
}
else if (n==3)
{
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a];
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b];
}
}
}
else if (n>3 && n<6 && g!=0)
{
c = strtol((l.substr(0,g)).c_str(), NULL, 10);
if (c<=19)
cout << t[0][c];
else if (g==2 && c>=20)
{
a=(c-(10*(c/10)));
c=(c/10)-1;
if (a==0)
cout << t[1][c] << " " << t[3][1]<<" ";
else
cout << t[1][c] << " " << t[0][a] << " " << t[3][1]<<" ";
}
c = strtol((l.substr(g,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a];
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b];
}
}
else if (n>3 && n<=6 && g==0)
{
c = strtol((l.substr(0,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a]<<" "<< t[3][1]<<" ";
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b]<<" "<< t[3][1]<<" ";
}
c = strtol((l.substr(3,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a];
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b];
}
}
else if (n>6 && n<9 && g!=0)
{
c = strtol((l.substr(0,g)).c_str(), NULL, 10);
if (c<=19)
cout << t[0][c];
else if (g==2 && c>=20)
{
a=(c-(10*(c/10)));
c=(c/10)-1;
if (a==0)
cout << t[1][c] << " " << t[3][2]<<" ";
else
cout << t[1][c] << " " << t[0][a] << " " << t[3][2]<<" ";
}
c = strtol((l.substr(g,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a]<<" "<< t[3][1]<<" ";
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b]<<" "<< t[3][1]<<" ";
}
c = strtol((l.substr(g+3,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a];
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b];
}
}
else if (n>6 && n<=9 && g==0)
c = strtol((l.substr(0,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a]<<" "<< t[3][2]<<" ";
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b]<<" "<< t[3][2]<<" ";
}
c = strtol((l.substr(3,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a]<<" "<< t[3][1]<<" ";
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b]<<" "<< t[3][1]<<" ";
}
c = strtol((l.substr(6,3)).c_str(), NULL, 10);
a=(c-(100*(c/100)));
c=(c/100);
if (a==0)
cout << t[2][c];
else if (a<=19)
cout << t[2][c] << " " << t[0][a];
else if (a>=20 && a<=99)
{
int b=(a-(10*(a/10)));
a=(a/10)-1;
if (b==0)
cout << t[2][c] << " " << t[1][a];
else
cout << t[2][c] << " " << t[1][a] << " " << t[0][b];
}
else
cout << "Program mial byc maksymalnie do 999 Mln" << endl;
};