题目:字符串顺时针旋转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."
}