25

闲来没事,睡觉前写了这个程序。

#include <cctype>
#include <string>
#include <iostream>
 
using namespace std;
 
void ToOtherCase(char &c) 
{
    if( isupper(c) )
        c = tolower(c); 
    else
        c = toupper(c);
}
 
void AllCase(string &sInput, int iIndex)
{
    if( iIndex == sInput.size() )   
    {   
        cout << sInput << endl;
        return;
    }   
 
    AllCase(sInput, iIndex + 1); 
 
    if( !isalpha(sInput[iIndex]) )
        return;
 
    ToOtherCase(sInput[iIndex]);
    AllCase(sInput, iIndex + 1); 
}
 
int main(int c, char **v)
{
    if( c != 2 ) 
    {   
        cout << "Usage: " << v[0] << " word" << endl;
        return 0;
    }   
    string sInput = v[1];
    AllCase(sInput, 0);
    return 0;
}

ps, 为什么我的网站这么慢?

Tagged with:
preload preload preload