12243 - Flowers Flourish from France

Moderator: Board moderators

Rezwanul Islam Maruf
New poster
Posts: 2
Joined: Thu Oct 13, 2011 2:14 am

12243 - Flowers Flourish from France

I cant understand where did I make mistake .. plz help me

Code: Select all

``````#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#include<iostream>
using namespace std;

int main()
{
int a,n,i,sum,cases=1,S,mod,j,p,len_n,len_j,len_mod;

while(1)
{
cin>>n;
if(n==0)break;
sum=0;
for(i=1;i<=n;i++)
{
cin>>a;

sum=sum+a;
}
if(n==1)cout<<"Case "<<cases++<<":\n"<<sum<<endl;

else if(sum==n || sum==0)cout<<"Case "<<cases++<<":\n"<<"0"<<endl;

else if(sum%n==0)
{
S=sum/n;

if(S>0)cout<<"Case "<<cases++<<":\n"<<S<<endl;

else cout<<"Case "<<cases++<<":\n"<<"- "<<-S<<endl;
}

else
{
if(sum>=0)
{

i=1;j=0;
while(n*i<sum)
{
j++,i++;
}
mod=sum%n;

for(i=2;i<max(mod,n);i++)
{
if(mod%i==0 && n%i==0)
{
mod=mod/i;
n=n/i;
i=2;
}
}

len_mod=len_j=len_n=0;

if(j==0)
{
i=mod;
while(i)
{
i=i/10;len_mod++;
}
i=n;
while(i)
{
i=i/10;len_n++;
}
printf("Case %d:\n",cases++);
for(i=0;i<len_n-1;i++)cout<<" ";
cout<<mod<<endl;
for(i=0;i<len_n;i++)cout<<"-";
cout<<endl;
cout<<n<<endl;

}

else
{

i=j;
while(i)
{
i=i/10;len_j++;
}
i=mod;
while(i)
{
i=i/10;len_mod++;
}
i=n;
while(i)
{
i=i/10;len_n++;
}
printf("Case %d:\n",cases++);
for(i=0;i<len_j || i<len_n;i++)cout<<" ";
printf("%d\n",mod);
printf("%d",j);
for(i=0;i<len_n;i++)cout<<"-";
cout<<endl;
for(i=0;i<len_mod || i<len_j;i++)cout<<" ";
printf("%d\n",n);

}

}

else
{
sum=-sum;
i=1;j=0;
while(n*i<sum)
{
j++,i++;
}
mod=sum%n;

for(i=2;i<max(mod,n);i++)
{
if(mod%i==0 && n%i==0)
{
mod=mod/i;
n=n/i;
i=2;
}
}

len_mod=len_j=len_n=0;

i=j;
while(i)
{
i=i/10;len_j++;
}
i=mod;
while(i)
{
i=i/10;len_mod++;
}
i=n;
while(i)
{
i=i/10;len_n++;
}
if(j==0)
{
printf("Case %d:\n",cases++);

for(i=0;i<len_n+1;i++)cout<<" ";
cout<<mod<<endl;
cout<<"- ";
for(i=2;i<len_n+2;i++)cout<<"-";
cout<<endl;
for(i=0;i<len_mod+1;i++)cout<<" ";
cout<<n<<endl;

}
else
{

printf("Case %d:\n",cases++);
for(i=0;i<len_j+2 || i<len_n+2;i++)cout<<" ";
printf("%d\n",mod);
cout<<"- ";
printf("%d",j);
for(i=2;i<len_n+2;i++)cout<<"-";
cout<<endl;
for(i=0;i<len_mod+2 || i< len_j+2;i++)cout<<" ";
printf("%d\n",n);
}
}

}

}
return 0;
}``````

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

12243 - Flowers Flourish from France

I found the sample input / output provided in the problem sufficient for testing / debugging.
Check input and AC output for over 7,500 problems on uDebug!

ssavi
New poster
Posts: 28
Joined: Thu Nov 20, 2014 9:57 pm

Re: 12243 - Flowers Flourish from France

Hi v1n1t ,
My code passed all test cases in the problem. But I am getting WA . Why ??? Please Help anyone .

Code: Select all

``````#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char a[100000];
int i, p, q;
while(1)
{
gets(a);
if(a[0]=='*')
break;
for(i=0;i<strlen(a);i++)
a[i]=toupper(a[i]);
p=0; q=0;
for(i=0;i<strlen(a);i++)
{
if(a[i]==' ' && ((a[i+1]>='A' && a[i+1]<='Z') || (a[i+1]>='a' && a[i+1]<='z')))
{
if(a[i+1]==a[0])
{p=1;}
else
q=1;
}
}
if(p==1 && q==0)
printf("Y\n");
else
printf("N\n");
}
return 0;
}
``````
I know I am a Failure Guy .

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 12243 - Flowers Flourish from France

Input

Code: Select all

``Why``
Acc Output

Code: Select all

``Y``
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

moudud99
New poster
Posts: 28
Joined: Fri Feb 08, 2013 1:40 pm

Re: 12243 - Flowers Flourish from France

My code passed all case I tasted with but getting WA.Please someone help.Thanks in advance.

Code: Select all

``````#include<bits/stdc++.h>
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(ara,n) memset(ara,n,sizeof ara)
#define loop(i,j,n) for(i=j;i<n;i++)
#define rloop(i,j,n) for(i=n;i>=j;i--)
#define INF 2147483647
//const int row[]={-1, -1, -1,  0,  0,  1,  1,  1};  // Kings Move
//const int col[]={-1,  0,  1, -1,  1, -1,  0,  1};  // Kings Move
//const int row[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int col[]={-1,  1, -2,  2, -2,  2, -1,  1};  // Knights Move
//const int row[]={-1,0,0,1,0};
//const int col[]={0,-1,1,0,0};
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int lcm(int a,int b)
{
return ((a*b)/gcd(a,b));
}

using namespace std;
/*char tolower(char c)
{
if(isupper(c))c='a'+(c-'A');
}*/
int main()
{
//FRO;
//FRU;
//std::ios_base::sync_with_stdio(false);
int a,b,c,i,j,k,tc,t;
int n,m,cnt=0,cnt1=0;
char s[100001],ch;
string ss;
while(gets(s))
{
ss.clear();
if(!strcmp(s,"*"))return 0;
int len=strlen(s);
n=m=0;//printf("%d\n",len);
for(i=0; i<s[i]!='\0'; i++)if(isupper(s[i]))s[i]=tolower(s[i]);
for(i=0; i<s[i]!='\0'; i++)
{
if(i==0)ss.pb(s[i]);
else if(isalpha(s[i])&& s[i-1]==' '){ss.pb(s[i]);}//printf("%d .%c.\n",i,s[i]);
}
ch=s[0];
int flg=0;
for(i=1;i<ss.size();i++)
{
if(ss[i]!=ss[i-1])flg=1;
}
if(flg)printf("N\n");
else printf("Y\n");
}
return 0;
}
``````