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,"  %*c   %d    %*c     %d  ",&x,&y)==2)
{
      g(y);
      printf("%d\n",x);
        }
else
{
      for(x=0,p=s;*p>64;++p)
       {
        x=x*26+*p-64;
        cout<<x<<" ";
       }
      printf("R%sC%d\n", p, x);
      }
  }
  return 0;
}

Comments

Popular posts from this blog

Getting Started With MEAN App Development with AngularJs , ExpressJs , NodeJs and MongoDB.

B. Dreamoon and WiFi :calculate no. of ways : recursive solution (branch and bound )

A. Dreamoon and Stairs : minimum steps to reach : recursion solution.