fork download
  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <cstring>
  4. const int N=2005;
  5. char Str[N+5];
  6. int a[N+5];
  7. int ret[N+5];
  8.  
  9. void div(int *A){
  10. int tmp=0,i;
  11. for (i=N;i>=0;i--){
  12. tmp=tmp*10+A[i];
  13. ret[i]=tmp/2;
  14. tmp%=2;
  15. }
  16. }
  17.  
  18. void dec(int *A){
  19. A[0]--;
  20. int i=0;
  21. while (A[i]<0){
  22. A[i]+=10;
  23. A[++i]--;
  24. }
  25. }
  26.  
  27. void output(int *A){
  28. int i;
  29. for (i=N;i>=0;i--)
  30. if (A[i]) break;
  31. printf("%d",A[i--]);
  32. for (;i>=0;i--) printf("%d",A[i]);
  33. }
  34.  
  35. void gao(){
  36. scanf("%s",Str);
  37. memset(a,0,sizeof(a));
  38. memset(ret,0,sizeof(ret));
  39. int i,j;
  40. for (i=strlen(Str)-1,j=0;i>=0;i--,j++) a[j]=Str[i]-'0';
  41. if (a[0]%2==0){
  42. div(a);
  43. memcpy(a,ret,sizeof(a));
  44. if (a[0]%2==0) dec(a);
  45. else{
  46. dec(a);
  47. dec(a);
  48. }
  49. output(a);
  50. }
  51. else{
  52. div(a);
  53. output(ret);
  54. }
  55. }
  56.  
  57. int main(){
  58. // freopen("input.txt","r",stdin);
  59. int Tc,i;
  60. scanf("%d",&Tc);
  61. for (i=1;i<=Tc;i++){
  62. gao();
  63. puts("");
  64. if (i!=Tc) puts("");
  65. }
  66. }
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void gao()’:
prog.cpp:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp: In function ‘int main()’:
prog.cpp:60: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout
Standard output is empty