| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
求助~已经考虑了首位是0的情况,但是仍然WA,大家能不能帮忙看看,谢谢。#include <iostream>
#include <cstdio>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;
main()
{
int n,i,j,num,ans[10]={0};
int start,end,step,pos1,pos2;
char name[51],tmp[51];
scanf("%d",&n);
while (n>0)
{
getchar();
gets(name);
scanf("%d %s",&num,tmp);
//printf("num=%d\n",num);
i=0;getchar();
while (i<num)
{
char content[100000];
gets(content);
int len=strlen(content);
//printf("len=%d\n",len);
//printf("content[0]=%c\n",content[0]);
if (content[0]!='+')
{
for (j=0;j<len;j++)
ans[content[j]-'0']+=1;
i++;
}
else
{
istringstream ss(content);
istringstream tt(content);
char plus;
int start,end,step;
string begin,teminal,pace;
ss >> plus >> start >> end >> step;
tt >> plus >> begin >> teminal >> pace;
int digit=begin.size();
// printf("digit=%d\n",digit);
i+=(end-start)/step+1;
printf("start=%d end=%d step=%d\n",start,end,step);
int number,counter=0;
for (j=start;j<=end;j+=step)
{
number=j;counter=0;
while (number>0)
{
ans[number%10]+=1;
number/=10;
counter++;
}
// printf("counter=%d\n",counter);
if (counter!=digit)
ans[0]+=digit-counter;
}
}
// printf("i=%d\n",i);
}
printf("%s\n",name);
printf("%d %s\n",num,tmp);
int sum=0;
for (i=0;i<=9;i++)
{
printf("Make %d digit %d\n",ans[i],i);
sum+=ans[i];
}
if (sum>1)
printf("In total %d digits\n",sum);
else
printf("In total 1 digit\n");
n--;
}
system("PAUSE");
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator