Really? I think you didn't - your program doesn't correctly read input with multiple cases (read the description of input format again, and pay attention to last sentence there), so it couldn't possible pass e.g. test cases posted above by Sedefcho.Obaida wrote:I tested all the cases but still WA.
455 - Periodic Strings
Moderator: Board moderators
Re: Help with 455
Re: Help with 455
after adding this line to my code:
I still got wA. While i checked the test cases above & they are all right. ![:oops:](./images/smilies/icon_redface.gif)
Code: Select all
if(n>0)getchar();
![:oops:](./images/smilies/icon_redface.gif)
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: Help with 455
Your variable 'found' can be used uninitialized on line 38.
g++ can detect and warn you automatically about such errors - always compile with g++ -Wall -W.
g++ can detect and warn you automatically about such errors - always compile with g++ -Wall -W.
Re: 455 - Periodic Strings
Any way i edited my code like this but still got wA.
Code: Select all
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
int main()
{
bool found=1;
int i,n,root,len,j,k;
char st[81];
scanf("%d",&n);
getchar();getchar();
while(n--)
{
gets(st);
len = strlen(st);
root = len/2;
found = 1;
for(i=1;i<=root;i++)
{
if(len%i==0)
{
found=1;
for(j=i;j<len;j+=i)
{
for(k=0;k<i;k++)
{
if(st[k] != st[j+k])
{
found = 0;
break;
}
}
if(!found)break;
}
}
if(found){printf("%d\n",i);break;}
}
if(found==0)printf("%d\n",len);
if(n>0)puts("");
if(n>0)getchar();
}
return 0;
}
I didn't have g++. could you give me a link to download the software.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 455 - Periodic Strings
Now your code doesn't work for strings of length 1.
But probably your current compiler too can warn you about uninitialized variables and other errors - look in its help. And there's also this great static code analysis tool - splint, which can detect even more errors.
Google mingw or cygwin - these are two ports of gcc to windows.I didn't have g++. could you give me a link to download the software.
But probably your current compiler too can warn you about uninitialized variables and other errors - look in its help. And there's also this great static code analysis tool - splint, which can detect even more errors.
Re: 455 - Periodic Strings
I got Acc in this problem.
Thank you so much.
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
Thank you so much.
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
-
- New poster
- Posts: 3
- Joined: Thu Jun 03, 2010 8:55 pm
Re: Problem 455: WA
i'm gettin' wa in this code...
need help
need help
Code: Select all
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,l,len,done,x,t;
char s[100],c[100];
scanf("%d",&t);
getchar();
for (x=1; x<=t; ++x)
{
getchar();
gets(s);
len=strlen(s);
for (i=1; i<=len; ++i)
{
for (j=0; j<i; ++j)
{
c[j]=s[j];
}
c[j]='\0';
done=1;
for (k=0,l=0; k<len; ++k,++l)
{
if (c[l]!=s[k])
{
done=0;
break;
}
if (l==j-1)
l=-1;
}
if (done==1)
{
printf("%d\n",j);
break;
}
}
if (x!=t)
printf("\n");
}
return 0;
}
455 - Periodic Strings
I'm ACM fresh and now I'm confused in the following code.I don't know where it has mistakes.So many times did I submit.Who can help me?
![:-?](./images/smilies/icon_confused.gif)
Code: Select all
#include <stdio.h>
#include <string.h>
int main()
{
char str[100], buf[10];
int i, j, len, flag, n;
scanf("%d%*c", &n);
while (n--)
{
gets(buf);
scanf("%s%*c", str);
len = strlen(str);
for (i=1; i<=len; i++)
{
flag = 1;
if (len%i==0)
{
for (j=i; j<len; j++)
{
if (str[j] != str[j%i])
{
flag = 0;
break;
}
}
if (flag)
{
printf("%d", i);
printf(n?("\n\n"):(""));
break;
}
}
}
}
return 0;
}
-
- New poster
- Posts: 1
- Joined: Mon Jan 03, 2011 10:45 pm
getting WA (455) please help
...just...getting... WA .. WA .. WA on 455 and can't determine where is the problem........would somebody...help...please....... :
Here is my code:
#include <stdio.h>
#include <string.h>
int main() {
char word[85];
unsigned long n,i, j, len;
scanf("%lu",&n);
while(n--){
scanf("%s", word);
len = strlen(word);
for(i=1;i<=len;i++)
if(len%i==0){
for(j=0;j+i<len;j+=i)
if(word[j]!=word[j+i]) break;
if(j+i>=len) break;
}
printf("%lu\n\n", i);
}
return 0;
}
![:evil:](./images/smilies/icon_evil.gif)
Here is my code:
#include <stdio.h>
#include <string.h>
int main() {
char word[85];
unsigned long n,i, j, len;
scanf("%lu",&n);
while(n--){
scanf("%s", word);
len = strlen(word);
for(i=1;i<=len;i++)
if(len%i==0){
for(j=0;j+i<len;j+=i)
if(word[j]!=word[j+i]) break;
if(j+i>=len) break;
}
printf("%lu\n\n", i);
}
return 0;
}
-
- New poster
- Posts: 5
- Joined: Mon Apr 30, 2012 10:15 am
Re: getting WA (455) please help
I am getting WA.. Please help sumone Here is my code:
Code: Select all
import java.io.*;
import java.util.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader x=new BufferedReader(new InputStreamReader(System.in));
int period=0,n=0,p=0,z=0,i=0,j=0,l=0,k=0;String s="",t="";
n=Integer.parseInt(x.readLine());
for(i=1;i<=n;i++)
{
s=x.readLine();s=x.readLine();l=s.length();
check:{
for(j=1;j<l;j++)
{
p=0;k=0;t="";period=0;
if(l%j==0)
{
p=0;k=0;t="";
z=l/j;
String a[]=new String[z];
for(k=0;k<l;k++)
{
if(t.length()==j)
{
a[p]=t;t="";p++;
}
t=t+s.charAt(k);
}
a[p]=t;
for(k=1;k<z;k++)
{
if(!(a[0].equals(a[k])))
{period=-1;break;}
}
if(period!=-1)
{
period=j;break check;
}
}
}
}
if(period==0 || period==-1)
period=l;
System.out.println(period);
if(i!=n)
System.out.println();
}
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: getting WA (455) please help
I like editing with xemacs, you can hit tab on a line to fix the indentation, which it also helps you with as you code.
As Scape pointed out, try reading input without depending on the line formatting being correct.
As Scape pointed out, try reading input without depending on the line formatting being correct.
Check input and AC output for thousands of problems on uDebug!
455 - Periodic Strings
getting WA...checked all cases
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int tc = in.nextInt();
while((tc--)>0)
{
String str = in.next();
int l = str.length();
boolean flag = false;
int i;
for(i = 1; i<=l/2; i++)
{
if(l%i != 0)
continue;
boolean check = true;
String sub = str.substring(0, i);
for(int j = 0; j < l/i; j++)
{
if(!sub.equals(str.substring(j*i, (j+1)*i)))
{
check = false;
break;
}
}
if(check)
{
flag = true;
break;
}
}
if(flag)
System.out.println(i);
else
System.out.println(l);
System.out.println();
}
}
}
import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int tc = in.nextInt();
while((tc--)>0)
{
String str = in.next();
int l = str.length();
boolean flag = false;
int i;
for(i = 1; i<=l/2; i++)
{
if(l%i != 0)
continue;
boolean check = true;
String sub = str.substring(0, i);
for(int j = 0; j < l/i; j++)
{
if(!sub.equals(str.substring(j*i, (j+1)*i)))
{
check = false;
break;
}
}
if(check)
{
flag = true;
break;
}
}
if(flag)
System.out.println(i);
else
System.out.println(l);
System.out.println();
}
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 455 - Periodic Strings
Two consecutive output are separated by a blank line. Don't print a blank line at the end.
Check input and AC output for thousands of problems on uDebug!
uva=455 i am gettign WA why.............
#include <iostream>
#include <string>
#define inf 1<<20
using namespace std;
string a;
int countSubstring(string sub)
{
if (sub.length() == 0) return 0;
int count = 0;
for (size_t offset = a.find(sub); offset != std::string::npos;
offset = a.find(sub, offset + sub.length()))
{
++count;
}
return count;
}
int main()
{
string s;int n,min;
cin>>n;
bool flag=false;
while(n--){
if(flag){cout<<endl;}
flag=true;
cin>>a;min=inf;
for(int i=0;i<a.size()/2;i++){
s+=a;
int sub_len=s.size();
int str_count=countSubstring(s);
if(sub_len*str_count==a.size()){
if(sub_len<min){
min=sub_len;
}
}
}
cout<<min<<endl;
a.erase();
s.erase();
}
return 0;
}
#include <string>
#define inf 1<<20
using namespace std;
string a;
int countSubstring(string sub)
{
if (sub.length() == 0) return 0;
int count = 0;
for (size_t offset = a.find(sub); offset != std::string::npos;
offset = a.find(sub, offset + sub.length()))
{
++count;
}
return count;
}
int main()
{
string s;int n,min;
cin>>n;
bool flag=false;
while(n--){
if(flag){cout<<endl;}
flag=true;
cin>>a;min=inf;
for(int i=0;i<a.size()/2;i++){
s+=a;
int sub_len=s.size();
int str_count=countSubstring(s);
if(sub_len*str_count==a.size()){
if(sub_len<min){
min=sub_len;
}
}
}
cout<<min<<endl;
a.erase();
s.erase();
}
return 0;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: uva=455 i am gettign WA why.............
Input:correct output:4
Code: Select all
1
asdf
Check input and AC output for thousands of problems on uDebug!