490 - Rotating Sentences

Moderator: Board moderators

unreleased
New poster
Posts: 16
Joined: Sun Nov 10, 2013 7:41 pm

Re: 490 - Rotating Sentences

why WA??

Code: Select all

``````#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <map>
#include <set>
#include <sstream>
#include <utility>
#include <bitset>

#define mx 1000000
#define INT 2147483647

#define D   double
#define L   long
#define LL  long long
#define ULL unsigned long long
#define SS stringstream

#define isc1(a)      scanf("%d", &a)
#define isc2(a,b)    scanf("%d%d", &a, &b)
#define isc3(a,b,c)  scanf("%d%d%d", &a, &b, &c)
#define llsc1(a)     scanf("%I64d", &a)
#define llsc2(a,b)   scanf("%I64d%I64d", &a, &b)
#define llsc3(a,b,c) scanf("%I64d %I64d %I64d", &a,&b,&c)

#define f(a,n)  for(a=0; a<n; a++)
#define all(a)  a.begin(), a.end()
#define ms(arr) memset(arr, 0, sizeof(arr))
#define cl(a)   a.clear()
#define sz(a)   a.size()

#define sc scanf
#define pf printf
#define pu push_back
#define pb pop_back
#define vc vector
#define mp make_pair
#define fi first
#define se second
#define pip pf("pip.....\n")

using namespace std;
char arr[1234][1234];
int main()
{
//freopen("input.txt", "r", stdin);
//clock_t start = clock();
int a=0,b,c=0,d, len, maxi=0;
string str, str1, str2;
ms(arr);
while(getline(cin, str))
{

len=sz(str);
if(len==0)break;
maxi=max(len, maxi);
for(a=0; a<len; a++)
arr[a][c]=str[a];
++c;
}

for(b=0; b<maxi; b++)
for(a=c-1; a>=0; a--)
{
if(!arr[b][a])pf(" ");
cout<<arr[b][a];
if(a==0)pf("\n");
}

//start = clock()-start;
//pf("\n%lf sec", start/(D)CLOCKS_PER_SEC);
return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 490 - Rotating Sentences

If you run your code on the sample input it looks like you're printing null chars at the end of the last two lines.
Check input and AC output for thousands of problems on uDebug!

the_mez
New poster
Posts: 2
Joined: Sun Jun 05, 2016 4:35 pm

Re: 490 - Rotating Sentences

gettting runtime error in uva-490
help me out

#include<iostream>
using namespace std;
int main()
{

string lines[100];
int i=0,max_len=0;
int x;
while(getline(cin,lines))
{
if (lines=="")
continue;
x=lines.length();
if (x>max_len)
max_len=x;
i++;

}
//cout<<max_len;
int m;
for(m=0;m<max_len;m++)
{
for(int k=i-1;k>=0;k--)
{
if (m<lines[k].length())
cout<<lines[k][m];
else
continue;
}
cout<<endl;
}

}