uva490 Rotating Sentences

题目:字符串顺时针旋转90度

注意:刚开始总报错,主要是因为字符串长度不一。输出的时候不会输出\0,所以尾部长短不一的地方就会造成错误。改正方法:当输出时,检测是不是\0,如果是则输出空格

#include <cstdio>
#include <string.h>
#include <cstdlib>
#include <cmath>
#include <ctgmath>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[]) {
	string m;
	char Output[110][110];
	memset(Output, 0, sizeof(Output));
	int j = 0;
	int length = 0;
	int max_length = 0;
	while(getline(cin,m)){
		length = m.length();
		if(length > max_length) max_length = length;
		for(int i = 0; i < m.length(); i ++){
			Output[i][j]=m[i];
		}
		j++;
	}
	for(int i = 0; i < max_length; i++){
		for(int m = j - 1; m >= 0; m--) {
		 	if(Output[i][m] == '\0') cout<<" ";//没有这句话总是WA
			else cout<<Output[i][m];
		}
		
		cout<<endl;
	}
	//"I think, therefore I am."
		
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值