11716 why CE ??

Write here if you have problems with your C++ source code

Moderator: Board moderators

11716 why CE ??

Postby dante » Fri Aug 10, 2012 4:44 pm

hi,

I'm getting CE for this code, I don't how to change it, can anyone help ?

Code: Select all
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
   int n;
   cin>>n;
   getchar();
   for(int i=1; i<=n; i++){
      char ciph[10010], deciph[10010];
      int len, sq;
      gets(ciph);
      len = strlen(ciph);
      sq = sqrt( (float)len );
      if( sq*sq != len ) cout<<"INVALID"<<endl;
      else{
         int dex=0;
         for(int j=0; j<sq; j++ )
            for(int k=0; k<sq; k++, dex++)
               deciph[dex] = ciph[ sq*k + j ];
         deciph[dex]=NULL;
         cout<<deciph<<endl;
      }
   }
   return 0;
}
dante
New poster
 
Posts: 3
Joined: Fri Aug 10, 2012 4:30 pm

Re: 11716 why CE ??

Postby brianfry713 » Fri Aug 10, 2012 10:09 pm

On my system using g++ I get these compile warnings:
Code: Select all
In function `int main()':
15: warning: assignment to `int' from `float'
15: warning: argument to `int' from `float'
22: warning: assignment to non-pointer type `char' from NULL
22: warning: argument to non-pointer type `char' from NULL
You can see your compile errors by clicking "My Submissions".
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11716 why CE ??

Postby dante » Sat Aug 11, 2012 12:28 am

tnx.

here is the msg I get from uva.

code.cpp: In function 'int main()':
code.cpp:9:10: error: 'getchar' was not declared in this scope
code.cpp:13:12: error: 'gets' was not declared in this scope
code.cpp:22:16: warning: converting to non-pointer type 'char' from NULL


I can replace "getchar" with "cin.ignore" but what should I use instead of "gets" ?
dante
New poster
 
Posts: 3
Joined: Fri Aug 10, 2012 4:30 pm

Re: 11716 why CE ??

Postby dante » Sat Aug 11, 2012 11:03 pm

Oops ! I found out the reason...
dante
New poster
 
Posts: 3
Joined: Fri Aug 10, 2012 4:30 pm


Return to C++

Who is online

Users browsing this forum: No registered users and 1 guest