这一场就是一个杯具,但是不得不说题目出得很有意思,质量很棒
A没的说
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int num[11]; int main(){ num[0] = 2; num[1] = 7; num[2] = 2; num[3] = 3; num[4] = 3; num[5] = 4; num[6] = 2; num[7] = 5; num[8] = 1; num[9] = 2; char str[3]; while(cin>>str){ int n; n=num[str[0]-‘0‘]*num[str[1]-‘0‘]; cout<<n<<endl; } return 0; }
?
B题我一直在思考如何把一个数分解为素数因子乘积的形式,实际上直接枚举0---sqrt的因子就可以了!
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> typedef long long ll; int main(){ ll a,b,i,j,k,res; while(scanf("%I64d%I64d",&a,&b)!=EOF){ if(a == b){ printf("infinity\n"); continue; } a -= b; if(a < 0){ printf("0\n"); continue; } res = 0; ll q = sqrt(a); for(i = 1; i <= q; i ++){ if(a % i== 0){ if(i>b){ res++; } if(a/i>b){ res++; } } } if(q > b && q*q == a){ res --; } printf("%I64d\n",res); } return 0; }
?
C题,直接把前面的#设成1个),把累积下来的(算到最后一个#上,最后注意要检查一遍括号是否匹配成功
#include<iostream> #include<cstdio> #include<cstring> #include<stack> #include<cmath> using namespace std; char str[100010]; int num[100010]; int main(){ int p, i, j, k, len, ans; while(cin>>str){ len = strlen(str); // str[len] = ‘#‘; p = 0; k = 0; bool flag = 1; for(i = 0; i< len; i++){ if(str[i] == ‘(‘){ p ++; }else{ if(str[i] == ‘)‘){ if(p<=0){ flag = 0; break; }else{ p --; } }else{ ///// ‘#‘ k ++; if(p<=0){ flag = 0; break; }else{ p --; } } } } if(!flag){ puts("-1"); continue; } flag = 1; p = 0; for(i = 0; i < len; i ++){ if(str[i] == ‘(‘){ p ++; } else{ p --; } } ans = p + 1; p = 0; j = 0; for(i = 0; i < len; i ++){ if(str[i] == ‘(‘){ p ++; } else{ if(str[i] == ‘)‘){ p --; }else{ j ++; if(j != k){ p --; }else{ p -= ans; } } } if(p<0){ flag = 0; break; } } if(!flag||p!=0){ puts("-1"); continue; } for(i = 0; i < k - 1; i ++){ printf("%d\n",1); }printf("%d\n",ans); } return 0; }
?
?
原文:http://bbezxcy.iteye.com/blog/2166245