← Back to topics
Topic

Tajna

M
Martin
this is my solution:

#include <iostream>
#include <string>
using namespace std;

int velicina (int b)
{
float c;
for (int i=b;i>=1;i--)
{
c=b/i;
if (int(c)==c && i<=c) return i;
}
}
int main (void)
{
string n;
cin >> n;
int b;
b=n.size();
int r,c;
r=velicina(b);
c=b/r;
int k=0;
char p[r][c];
for (int i=0;i<c;i++)
{
for (int j=0;j<r;j++)
{
p[j][i]=n[k];
k++;
}
}
for (int i=0;i<r;i++)
{
for (int j=0;j<c;j++)
{
cout << p[i][j];
}
}
return 0;
}

every example below the task works, but it fails everything when i send it.
can anybody help me or say what i'm doing wrong. i cant find out why me solution is failing.
g
goran_f2
don't use float, always use double, and the line c=b/i; should be c=(double)b/(double)i;
M
Martin
thanks, now it works perfectly.
D
Diabolic
Still, my code is showing all wrong results. What's the problem?
D
Diabolic
Za svih testova imam Wrong Result, a 100 puta sam provjerio i sve je ok. U cemu je problem?