I can't understand why I got PE.
For each test case, I generate a string then I print it until the latest letter, throwing away the latest '_'s.
I've been tried print two '\n' at final and also one.
please, help me!!!
- Code: Select all
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
void print_trim(string *s) {
int index = -1;
for(int i = 0; i < s->size(); i++){
if(s->at(i) != '_'){
index = i;
}
}
if(index == -1) {
cout << *s << endl;
return;
}
for(int i = 0; i <= index; i++){
if(s->at(i) == '_') printf(" ");
else if(s->at(i) == '\\') printf("\n");
else printf("%c", s->at(i));
}
printf("\n");
}
int main(int argc, char **argv) {
int n;
char line[150][150];
while (scanf("%d", &n) != EOF) {
for(int i =0;i<n;i++){
scanf("%s", line[i]);
}
string aux;
int size = strlen(line[0]);
for(int j=size-1; j >= 0; j-- ){
for(int i = n-1; i >= 0; i--) {
aux += line[i][j];
}
}
if(!aux.empty()){
print_trim(&aux);
}
printf("\n");
}
return (0);
}
sorry my poor English.
