fork(2) download
  1. /*"The Woods are lovely dark and deep,
  2. But i have promises to keep,
  3. Miles to go before i sleep and Miles to go before i Sleep"
  4. */
  5. #include<stdio.h>
  6. #include<set>
  7. #include<iostream>
  8. #include<stack>
  9. #include<math.h>
  10. #include<vector>
  11. #include<string.h>
  12. #include<algorithm>
  13. #define pb(n) push_front(n)
  14. #define M(ch) memset(ch,0,sizeof(ch))
  15. unsigned long long mod=1000000007;
  16. using namespace std;
  17. char ch[1000009];
  18. int t;
  19. int check[1000009];
  20. int main()
  21. {
  22. char replace[100][2];
  23. cin>>t;
  24. while(t--)
  25. {
  26. M(ch);
  27. M(replace);
  28. M(check);
  29. int pos,n,len,flag;
  30. flag=0;
  31. cin>>n;
  32. for(int i=0;i<n;i++)
  33. {
  34. cin>>replace[i][0];
  35. cin>>replace[i][1];
  36. }
  37. cin>>ch;
  38. len=strlen(ch);
  39. if(n)
  40. {
  41. for(int i=0;i<len;i++)
  42. {
  43.  
  44. for(int j=0;j<n;j++)
  45. {
  46.  
  47. if((ch[i]==replace[j][0])and(check[i]==0))
  48. {
  49. ch[i]=replace[j][1];
  50. check[i]=1;
  51. //if(replace[j][i]=='.')
  52. //flag=1;
  53. //break;
  54.  
  55. }
  56. }
  57.  
  58. }
  59.  
  60. }
  61. int count=0;
  62. char *ptr=NULL;
  63. ptr=strchr(ch,'.');
  64. if(ptr!=NULL)
  65. {
  66. pos=ptr-&ch[0]; //POSITION AT WHICH THE ' . ' IS PRESENT
  67. //cout<<"Point found at "<<pos<<endl;
  68. for(int i=len-1;i>=pos;i--)
  69. {
  70. if(ch[i]!='0')
  71. {
  72. //flag=1;
  73. break;
  74. }
  75. else if(ch[i]=='0')
  76. {
  77. count++;
  78. ch[i]='\0';
  79. }
  80. }
  81. if(count+1==len-pos)
  82. ch[pos]=0;
  83. }
  84.  
  85. //cout<<"Count="<<count<<endl<<"Len-pos="<<len-pos<<endl;
  86.  
  87.  
  88. //if(flag)
  89. {
  90. /*int tmp=len-1;
  91. for(tmp;ch[tmp]=='0';)
  92. {
  93. ch[tmp]=0;
  94. tmp-=1;
  95. }*/
  96. int tmp=0;
  97. for(tmp=0;ch[tmp]=='0';)
  98. {
  99. tmp++;
  100.  
  101. }
  102. char *q=&ch[tmp];
  103. if(ch[tmp]!=0)
  104. cout<<q<<endl;
  105. else
  106. cout<<"0\n";
  107.  
  108. }
  109.  
  110. /*else
  111. {
  112. double ans;
  113. //cout<<ch<<endl;
  114. ans=atof(ch);
  115. cout<<ans<<endl;
  116. }/*
  117.  /*/
  118. }
  119. //system("pause");
  120. return 0;
  121. }
Success #stdin #stdout 0s 8180KB
stdin
1
2
3 5
5 3
535
stdout
353