U E D R , A S I H C RSS

데블스캠프2006/화요일/pointer/문제2/김준석

문제2 reverse



#include<iostream>
using namespace std;

void reverse(char a[],int lengh){

        char *b = new char[lengh+1];
        for(int i=0; i<lengh; i++)
                b[i] = a[lengh-i-1];

        b[lengh] = a[lengh];

        for(i=0;i<lengh;i++)
                     a[i] = b[i];

        delete [] b;
}


void main(){

        int i=0,lengh=0;
        char *a = new char[256];
        cin >> a;
        while(a[i++] != '\0')
        {
                lengh++;
        }

        cout << lengh << endl;

        reverse(a,lengh);

        cout << a << endl;

        delete [] a;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:29:06
Processing time 0.0185 sec