fork(3) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define s(n) scanf(" %d",&n)
  5. #define sll(n) scanf("%lld",&n)
  6. #define p(n) printf("%d\n",n)
  7. #define pll(n) printf("%lld\n",n)
  8. #define pnl printf("\n");
  9.  
  10. //qsort (a,t, sizeof(*a), comp); //library function.array pointer,no. of elemn,size of 1 elmnt,comparison function
  11. //for(i=0;i<t;i++) printf("%d \n",a[i]);//print array
  12.  
  13. /*int gcd (long long int a,long long int b)
  14. { int temp;
  15.  while (b != 0) { temp = b; b = a % b; a = temp; }
  16.  return a; }
  17. */
  18.  
  19. /*int comp (const void * a, const void * b)
  20. {
  21.   return *(int*)a - *(int*)b;
  22. }*/
  23.  
  24. int main()
  25. {//freopen("input.txt","r",stdin);//redirects standard input
  26. //freopen("output.txt","w",stdout);//redirects standard output
  27. int i,t,n,len,j,k;
  28. int *repl=(int *)calloc(1000000,sizeof(int));
  29. if(repl==NULL) return -1;
  30. char c[95],p[95];
  31. char *s=(char *)malloc(1000000*(sizeof(char)));
  32. if(s==NULL) return -1;
  33. s(t);
  34.  
  35. while(t--)
  36. {s(n);
  37. for(i=0;i<n;i++) {scanf(" %c %c",&c[i],&p[i]);}
  38.  
  39. scanf("%s",s);
  40. len=strlen(s);
  41.  
  42.  
  43. for(i=0;i<n;i++)
  44. {
  45. for(j=0;j<len;j++)
  46. {
  47. if(s[j]==c[i])
  48. {
  49. if(repl[j]==0)
  50. {
  51. s[j]=p[i];
  52. repl[j]=1;
  53. }
  54. }
  55. }
  56. }
  57.  
  58. if(len==1) {if (s[0]!='.') printf("%s",s); else printf("0");}
  59. else {
  60. for(i=0;s[i]=='0';i++);
  61. if(i==len) printf("0");
  62. else {
  63. for(k=i;(s[k] != '.') && (k<len);k++) { printf("%c",s[k]);}
  64. if(k!=len)
  65. {
  66. for(j=len-1;s[j]=='0';j--);
  67. if(k!=j) {for(;k<=j;k++)printf("%c",s[k]);} else{if(i==j) printf("0");}
  68.  
  69. }
  70. }
  71. }
  72. pnl;
  73. }
  74. free(repl);
  75. free(s);
  76. //system("pause");
  77. return 0;
  78. }
  79.  
  80.  
Success #stdin #stdout 0s 2296KB
stdin
5
0
00000
0
0000.000
0
.0000
0
00045.000045000
0
55565.
stdout
0
0
0
45.000045
55565