ACM菜鸟问水题
HDOJ1061 http://acm.hdu.edu.cn/showproblem.php?pid=1061
很水的一道题,可为什么会WA呢?
#include<stdio.h>
int main()
{
int a[10][4]={{0},{1},{2,4,8,6},{3,9,7,1},{4,6},{5},{6},{9,3,1,7},{8,4,2,6},{1,9}};
int b[10]={1,1,2,4,2,1,1,4,4,2};
int unit,t,num,index;
while(scanf("%d",&t)!=EOF&&t)
{
while(t--)
{
scanf("%d",&num);
unit=num%10;
if(num%b[unit]==0)
index=b[unit];
else
index=num%b[unit];
printf("%d\n",a[unit][index-1]);
}
}
}
[解决办法]
没仔细看,发现个错误
a[7][] = {7,9,3,1}
[解决办法]
//大一写的#include <stdio.h>int f(int n){ int m=n%10; int a[10][4]={{0},{1},{6,2,4,8},{1,3,9,7},{6,4},{5},{6},{1,7,9,3},{6,8,4,2},{1,9}}; if(m==0||m==1||m==5||m==6) return m; else if(m==4||m==9) return a[m][n%2]; else return a[m][n%4];}int main(void){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int n; scanf("%d",&n); while(n--) { int x; scanf("%d",&x); printf("%d\n",f(x)); } return 0;}
[解决办法]
你确定没有t=0的
如果有t=0,后面还有好几组,那你 的程序岂不是退出了?