Posts

Showing posts with the label String Handling

use of sscanf , takes interger from messy string R23C55.. or R2323434C44554

                                          http://codeforces.com/contest/1/problem/B                                                       B. Spreadsheets 55 = BC 27 = AA 28 = AB sscanf takes out number from a messy string input : for example : if the input is R5564C757 , it takes (sscanf(s,"  %*c   %d    %*c     %d  ",&x,&y);  x=5564  y=757 #include<cstdio> #include<bits/stdc++.h> using namespace std; void g(int t) {  if(t)  {  g((t-1)/26);  putchar(65+(t-1)%26);  } } int main() {   int n,x,y;   char s[64],*p;   for(scanf("%d ",&n);n--;)   {     gets(s);     if(sscanf(s,"  ...

string handling -- Dubstep

                                 http://codeforces.com/problemset/problem/208/A                                      A. Dubstep In this question , we have to remove all "WUB" from a given string. Sample test(s) input WUBWUBABCWUB output ABC input WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB output WE ARE THE CHAMPIONS MY FRIEND #include<bits/stdc++.h> using namespace std; int main() {  string s,s1;  cin>>s;  s1="WUB";  int i,j,k,l;  l=s.length();   k=s.find(s1);               /// "find()" returns the starting index of s1 in s  while(k!=-1)  {     s.replace(k,3," ");      /// "replace()" function replace  the 3 letters starting from kth ...