Page 1 of 2

Re: please help me why i am getting WA for my code ?

Posted: Fri Oct 05, 2012 12:25 pm
by atul
Problem no 1225 ,,,
I am getting WA.. plz help

this is my code

#include <stdio.h>
#include <stdlib.h>

int main()
{
int a[20],i,j,n,m,b,g,s;
scanf("%d",&n);
for(s=1;s<=n;s++)
{
for(i=0;i<20;i++)
{
a=0;
}
scanf("%d",&m);
for(i=1;i<=m;i++)
{
g=i;
if(i<10)
{
a=a+1;
}
else
{
while(g!=0)
{
b=g%10;
g=g/10;
a=a+1;
}
}
}

for(j=0;j<=9;j++)
{
printf("%d",a[j]);
printf(" ");
}
if(s!=n)
printf("\n");
}
return 0;
}

Re: please help me why i am getting WA for my code ?

Posted: Fri Oct 05, 2012 7:29 pm
by brianfry713
Don't print a space at the end of a line.

1225 - Digit Counting

Posted: Sat Feb 08, 2014 3:31 pm
by uDebug
Here's some input / output I found useful while testing / debugging.

There's no extra space after the 10th number in the output.

Input:

Code: Select all

4
9999
22
71
649
AC Output:

Code: Select all

2889 4000 4000 4000 4000 4000 4000 4000 4000 4000
2 13 6 2 2 2 2 2 2 2
7 18 17 17 17 17 17 9 7 7
124 235 235 235 235 225 175 125 125 125

Re: 1225 - Digit Counting

Posted: Sat Mar 29, 2014 10:58 am
by vsha041
Thanks. But the strange part is that for some of the problems we don't get presentation error even if we put an extra space/spaces after the last number.

Re: 1225 - Digit Counting

Posted: Mon Mar 31, 2014 11:17 pm
by brianfry713
On problems with a special judge you may be able to get away with extra spaces and still get AC.

Re: 1225 - Digit Counting

Posted: Wed Apr 02, 2014 10:50 am
by vsha041
brianfry713 wrote:On problems with a special judge you may be able to get away with extra spaces and still get AC.
oh okay, thanks brian, actually i have made a rule to not put spaces if they haven't asked for as this has caused lot of suffereing. That's because in some cases extra spaces give wrong answer instead of presentation errors.

Re: 1225 - Digit Counting

Posted: Wed Apr 02, 2014 10:58 am
by uDebug
vsha041 wrote:That's because in some cases extra spaces give wrong answer instead of presentation errors.
Yes. Don't count on extra spaces and / or newlines to give you a PE. More often than not, you'll get a WA (and this can be misleading).

Re: 1225 - Digit Counting

Posted: Sat May 17, 2014 8:52 pm
by Mrsuit
Hey, i have the same problem, first i got PE, then i fixed a little thing about the spaces, but now i got WA. And it's because that thing, when i put

Code: Select all

9999
22
71
649
i got

Code: Select all

2889 4000 4000 4000 4000 4000 4000 4000 4000
2 13 6 2 2 2 2 2 2
7 18 17 17 17 17 17 9 7
124 235 235 235 235 225 175 125 125
So, how can i fix this?.
Thanks

Re: 1225 - Digit Counting

Posted: Tue May 20, 2014 10:16 pm
by brianfry713
Post your code

Re: 1225 - Digit Counting

Posted: Wed May 21, 2014 6:02 am
by Mrsuit
brianfry713 wrote:Post your code

Code: Select all

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {
public static void main(String[] args) throws NumberFormatException, IOException {
	BufferedReader bf = new  BufferedReader(new InputStreamReader(System.in));
	StringBuilder n = new StringBuilder();
	int i=Integer.parseInt(bf.readLine());
	StringBuilder sb= new StringBuilder();
	
	while (i>0){
		sb.delete(0,sb.length());
		int j=Integer.parseInt(bf.readLine());
		int [] numbers = new int [10];
		for (int k = 0; k < numbers.length; k++) {
			numbers[k]=0;
		}
		while (j>0){
			sb.append(j);
			j-=1;
		}
		String line=sb.toString();
		String [] list= line.split("");
		
		for (int k = 1; k < list.length; k++) {
			if(Integer.parseInt(list[k])==0){
				numbers[0]=numbers[0]+1;
			}
			if (Integer.parseInt(list[k])==1){
				numbers[1]=numbers[1]+1;
			}
			if (Integer.parseInt(list[k])==2){
				numbers[2]=numbers[2]+1;
			}
			if (Integer.parseInt(list[k])==3){
				numbers[3]=numbers[3]+1;
			}
			if (Integer.parseInt(list[k])==4){
				numbers[4]=numbers[4]+1;
			}
			if (Integer.parseInt(list[k])==5){
				numbers[5]=numbers[5]+1;
			}
			if (Integer.parseInt(list[k])==6){
				numbers[6]=numbers[6]+1;
			}
			if (Integer.parseInt(list[k])==7){
				numbers[7]=numbers[7]+1;
			}
			if (Integer.parseInt(list[k])==8){
				numbers[8]=numbers[8]+1;
			}
			if (Integer.parseInt(list[k])==9){
				numbers[9]=numbers[9]+1;
			}
		}
		for (int k = 0; k < numbers.length; k++) {
			if (k<8){	
			n.append(numbers[k]);
			}
			if (k==9){
				n.append(numbers[k]);
			}
		}	
		n.append("\n");
			
			
	
	
		
		i-=1;
	}
	System.out.println(n.substring(0,n.length()-1));	
	
		
		
	
		
	}
}

		
		
		
		
		
		
		
		

		
		
		
		
		
		



		
		




Thank you so much!

Re: 1225 - Digit Counting

Posted: Wed May 21, 2014 8:26 pm
by brianfry713
For the sample input, you're printing:
011100000
162211111
Instead of:
0 1 1 1 0 0 0 0 0 0
1 6 2 2 1 1 1 1 1 1

Re: 1225 - Digit Counting

Posted: Wed May 21, 2014 9:46 pm
by Mrsuit
brianfry713 wrote:For the sample input, you're printing:
011100000
162211111
Instead of:
0 1 1 1 0 0 0 0 0 0
1 6 2 2 1 1 1 1 1 1
I already fixed it, and got AC. Thank you!.

Re: 1225 - Digit Counting

Posted: Sat Oct 18, 2014 6:53 pm
by minor_coder
Can't understand what is the problem? at first i got PE then fixing the spaces now WA. Please help

Code: Select all

#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin>>n;
	for (int i = 0; i < n; i++)
	{
		int input;
		cin>>input;
		vector<int> result(10,0);
		for (int j = 1; j <= input; j++)
		{
			string s = to_string(j);
			for (int k = 0; k < s.length(); k++)
			{
				char ch = s[k];
				int x = ch - 48;
				result[x]++;
			}			
		}
		for (int j = 0; j < 10; j++)
		{
			if(j != 0 && i!= 9)
				cout<<" ";
			cout<<result[j]; 
		}
		if(i != n-1)
			cout<<endl;
	}
	return 0;
}

Re: 1225 - Digit Counting

Posted: Sat Oct 18, 2014 7:08 pm
by lighted
Change code to

Code: Select all

for (int j = 0; j < 10; j++)
{
    if (j != 0)
        cout << " ";

    cout << result[j]; 
}
cout << endl;
Don't forget to remove your code after getting accepted. 8)

Re: 1225 - Digit Counting

Posted: Sat Oct 25, 2014 9:22 pm
by xrenon
DELETED
Thank You