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 |
Re:谁能给一组测试数据,实在wa的不行了1In Reply To:Re:谁能给一组测试数据,实在wa的不行了 Posted by:6233843 at 2006-07-25 12:34:01 > #include <string> > #include <algorithm> > #include <iostream> > using namespace std; > //#include <fstream> > //using namespace std; > //ifstream cin("t.in"); > //ofstream cout("t.out"); > > > char data[16][90]; > char no[10],b[4],temp[2]; > > int main() > { > scanf("%s",data[0]); > while (1 ) > { > if (strcmp(data[0],"-1") == 0) return 0; > int i; > for ( i=0;i<15;i++) > { > memset(no,0,sizeof(no)); > for (int j=0;data[i][j] != 0;j++) > { > no[data[i][j]-'0']++; //算出了一个串中所有数字的个数 > } > for (int k=0;k<10;k++) //把新算得串加入下一个串中 > { > if (no[k] != 0 && no[k] < 10) > { > temp [0] = no[k] + '0'; > temp [1] = k + '0'; > strcat(data[i+1],temp); > memset(temp,0,sizeof(temp)); > } > else if (no[k] >=10) //如果某位的个数超过10 就要单独处理 > { > int p,m= no[k]; > for (p=1;m != 0;p--) > { > b[p] = m%10 + '0'; > m = m /10; > } > b[2] = k+'0'; > b[4] = '\0'; > strcat (data[i+1],b); > memset(b,0,sizeof(b)); > } > > } > } > int flag = 0; > int stop = 0; > for (i=0;i<15;i++) > { > int min; > if (strcmp(data[i],data[i+1]) == 0 ) > { > if ( i == 0 ) > { > printf("%s is self-inventorying\n",data[0]); > stop =1; > break; > } > else > { > printf("%s is self-inventorying after %d steps\n",data[0],i); > stop=1; > break; > } > } > else > { > for (int k=i+2;k+i<=15;k++) > { > if (strcmp(data[i],data[k]) == 0 ) > { > if (flag == 0) //如果flag为0 则记录下k-i的值 > { > min = k-i; > flag =1; > } > else //如果flag为1 则要比较min与k-i的值 并且找出最小的来 > { > if (min > k-i) > { > min = k-i; > } > } > } > } > } > if (flag) //如果flag为1 则说明有环的情况 > { > printf("%s enters an inventory loop of length %d\n",data[0],min); > stop =1; > break; > } > } > if (stop == 0) > printf("%s can not be classified after 15 iterations\n",data[0]); //如果stop为0 说明没有求出正确的解 输出没有解 > memset(data,0,sizeof(data)); //给data清0 > scanf("%s",data[0]); //重新读入下一组值 > } > } > 大家看看是不是因为我的char数据没有处理好?? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator