1225 - Digit Counting
Moderator: Board moderators
Re: please help me why i am getting WA for my code ?
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;
}
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;
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: please help me why i am getting WA for my code ?
Don't print a space at the end of a line.
Check input and AC output for thousands of problems on uDebug!
1225 - Digit Counting
Here's some input / output I found useful while testing / debugging.
There's no extra space after the 10th number in the output.
Input:
AC Output:
There's no extra space after the 10th number in the output.
Input:
Code: Select all
4
9999
22
71
649
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
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 1225 - Digit Counting
On problems with a special judge you may be able to get away with extra spaces and still get AC.
Check input and AC output for thousands of problems on uDebug!
Re: 1225 - Digit Counting
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.brianfry713 wrote:On problems with a special judge you may be able to get away with extra spaces and still get AC.
Re: 1225 - Digit Counting
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).vsha041 wrote:That's because in some cases extra spaces give wrong answer instead of presentation errors.
Re: 1225 - Digit Counting
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
i got
So, how can i fix this?.
Thanks
Code: Select all
9999
22
71
649
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
Thanks
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 1225 - Digit Counting
Post your code
Check input and AC output for thousands of problems on uDebug!
Re: 1225 - Digit Counting
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));
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 1225 - Digit Counting
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
011100000
162211111
Instead of:
0 1 1 1 0 0 0 0 0 0
1 6 2 2 1 1 1 1 1 1
Check input and AC output for thousands of problems on uDebug!
Re: 1225 - Digit Counting
I already fixed it, and got AC. Thank you!.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
-
- New poster
- Posts: 2
- Joined: Tue Sep 15, 2009 9:46 am
Re: 1225 - Digit Counting
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
Change code to
Don't forget to remove your code after getting accepted. 
Code: Select all
for (int j = 0; j < 10; j++)
{
if (j != 0)
cout << " ";
cout << result[j];
}
cout << endl;

A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
Re: 1225 - Digit Counting
DELETED
Thank You
Thank You
Last edited by xrenon on Sun Oct 26, 2014 11:17 am, edited 1 time in total.