1
The Waste Land / Re: C++ garbage
« on: December 20, 2006, 09:44:07 am »
#include<iostream>
#include<string>
using namespace std;
class PhoneNumber
{
bool Parse()
{
string numbers = "1234567890x";
string temp = "";
for ( int i = 0; i < Full.length(); i++ )
{
for ( int j = 0; j < numbers.length(); j++ )
{
if ( Full == numbers[j] )
{
temp += Full;
j = -1;
i++;
if ( i == Full.length() )
break;
}
}
}
Full = temp;
int xLoc = Full.find('x');
int acLoc = 0;
switch ( xLoc )
{
case 10:
acLoc = 3;
break;
case 7:
acLoc = 0;
break;
case -1:
xLoc = Full.length();
acLoc = 3;
if ( Full.length() == 7 )
acLoc = 0;
else if ( Full.length() == 10 )
acLoc = 3;
else
{
cout << "too long" << endl;
return false;
}
break;
default:
cout << "something else" << endl;
return false;
}
for ( int i = 0; i < Full.length(); i++ )
{
if ( i < acLoc )
AreaCode += Full;
else if ( i < xLoc )
{
Number += Full;
if ( Number.length() == 3 )
Number += '-';
}
else if ( i != xLoc )
Extension += Full;
}
return true;
}
public:
string Full, AreaCode, Number, Extension;
PhoneNumber()
{
Full = "";
AreaCode = "";
Number = "";
Extension = "";
}
PhoneNumber(string buffer)
{
Full = buffer;
AreaCode = "";
Number = "";
Extension = "";
}
bool IsValid()
{
return Parse();
}
};
void main()
{
PhoneNumber MyNumber;
string input;
cin >> input;
MyNumber.Full = input;
cout << MyNumber.IsValid() << endl;
cout << "(" << MyNumber.AreaCode << ")" << " " << MyNumber.Number << "x" << MyNumber.Extension << endl;
cout << MyNumber.Full << endl;
}
#include<string>
using namespace std;
class PhoneNumber
{
bool Parse()
{
string numbers = "1234567890x";
string temp = "";
for ( int i = 0; i < Full.length(); i++ )
{
for ( int j = 0; j < numbers.length(); j++ )
{
if ( Full == numbers[j] )
{
temp += Full;
j = -1;
i++;
if ( i == Full.length() )
break;
}
}
}
Full = temp;
int xLoc = Full.find('x');
int acLoc = 0;
switch ( xLoc )
{
case 10:
acLoc = 3;
break;
case 7:
acLoc = 0;
break;
case -1:
xLoc = Full.length();
acLoc = 3;
if ( Full.length() == 7 )
acLoc = 0;
else if ( Full.length() == 10 )
acLoc = 3;
else
{
cout << "too long" << endl;
return false;
}
break;
default:
cout << "something else" << endl;
return false;
}
for ( int i = 0; i < Full.length(); i++ )
{
if ( i < acLoc )
AreaCode += Full;
else if ( i < xLoc )
{
Number += Full;
if ( Number.length() == 3 )
Number += '-';
}
else if ( i != xLoc )
Extension += Full;
}
return true;
}
public:
string Full, AreaCode, Number, Extension;
PhoneNumber()
{
Full = "";
AreaCode = "";
Number = "";
Extension = "";
}
PhoneNumber(string buffer)
{
Full = buffer;
AreaCode = "";
Number = "";
Extension = "";
}
bool IsValid()
{
return Parse();
}
};
void main()
{
PhoneNumber MyNumber;
string input;
cin >> input;
MyNumber.Full = input;
cout << MyNumber.IsValid() << endl;
cout << "(" << MyNumber.AreaCode << ")" << " " << MyNumber.Number << "x" << MyNumber.Extension << endl;
cout << MyNumber.Full << endl;
}