首页 > 其他 > 详细

字符串倒序输出

时间:2014-02-27 22:03:50      阅读:511      评论:0      收藏:0      [点我收藏+]

读入空格跳出,其余不变;getchar()单字符读入判断直接TLE;

用到scnaf( "%[^ ]", str );表示读入除‘ ‘以外的所有字符;

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

const int maxn = 1005;
char str[ maxn ], ch[ 5 ], k;
int main(){
        while( scanf( "%[^ ]", str ) == 1 ){
            ;    
        }
    //printf( "1111111111" );k = strlen( str );
        k = strlen( str );
        for( int i = k - 1; i >= 0; --i )
            cout << str[ i ];
        cout << endl;    
        
    return 0;
}


TLE

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

const int maxn = 1005;
char str[ maxn ], ch, k;
int main(){
		k = 0;
		while( ( ch = getchar() )!= ‘ ‘ ){
			str[ k++ ] = ch;	
		}
		for( int i = k - 1; i >= 0; --i )
			cout << str[ i ];
		cout << endl;	
	return 0;
}


字符串倒序输出,布布扣,bubuko.com

字符串倒序输出

原文:http://blog.csdn.net/bo_jwolf/article/details/19999125

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!