Page 15 of 15

Re: 490 - Rotating Sentences

Posted: Sun Feb 15, 2015 8:48 pm
by unreleased
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;
}

Re: 490 - Rotating Sentences

Posted: Tue Feb 17, 2015 11:40 pm
by brianfry713
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.

Re: 490 - Rotating Sentences

Posted: Wed Jun 08, 2016 8:07 pm
by the_mez
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;
}

}