zoukankan      html  css  js  c++  java
  • toj 2971 Rotating Numbers

    2971.   Rotating Numbers
    Time Limit: 1.0 Seconds   Memory Limit: 65536K
    Total Runs: 262   Accepted Runs: 86



    As CSE students you are already familiar with the binary rotation. Now you should try to do something different like decimal number rotation. It is simple to rotate a decimal number for a single digit to the left to perform left rotation - just place the rightmost digit to the leftmost position as in the following:

    12345 => 51234

    If we gradually perform the left rotation operation for more and more times we have

    51234 => 45123

    45123 => 34512 and this way.

    But you should be careful to remember that leading zeros in decimal numbers does not carry any significance. Therefore, you need not to add leading zeros.

     

    Input

    Each input line consist of an integer M and another integer N. M denotes the number to be left rotated and N indicates how many times to rotate. Both M and N will fit 32-bit integers. Input is terminated by end of file.

     

    Output

    The output line contains the number after left rotation is performed on M for N times.

     

    Sample Input

    12345 3

    1800576 5

    10002 5

    Sample Output

    34512

    57618

    12

    _____________________________________________________________________

    Samina Azad (CSE-03)



    Source: CUET Easy Contest
    Submit   List    Runs   Forum   Statistics

    #include <iostream>
    #include 
    <string>
    #include 
    <cmath>
    using namespace std;
    int Get(string str)
    {
        
    int sum=0;
        
    int i,len=str.length(),k=0;
        
    for(i=len-1;i>=0;i--)
        {
            sum
    +=(int)((str[i]-'0')*pow(10.0,k++));
        }
        
    return sum;
    }
    int main()
    {
        
    string str;
        
    int n,i,len;
        
    while(cin>>str)
        {
            cin
    >>n;
            len
    =str.length();
            
    int num=0;
            
    for(i=0;i<len;i++)
                
    if(str[i]=='0')
                    num
    ++;
                
    int ss = 0 , kk;
            
    int j=len-1,k;
            
    int  t = len - num;
            
    bool mark=false;
            
    for(i=0;i<n;i++)
            {
                
    if(num == 0)
                {
                    ss
    =i;
                    mark
    =true;
                    
    break;
                }
                
    char ch=str.at(j);
                str.erase(j);
                
    if(ch!='0')
                    str
    =ch+str;
                
    else
                {
                    j
    --;
                    num
    --;
                }
            }
            
    if (!mark)
              printf(
    "%d\n",Get(str));
            
    else
            {
              kk 
    = n - ss;
              ss 
    = kk % t;
              
    for (i = 1 ; i <=ss ; ++ i)
              {
                  
    char temp=str.at(t-1);
                  str.erase(t
    -1);
                  str
    =temp+str;
              }
              printf(
    "%d\n",Get(str));
            }
        }
        
    return 0;
    }
  • 相关阅读:
    php之curl实现http与https请求的方法
    Linux学习之CentOS(十)--虚拟机下的CentOS如何上网
    php--yii2框架错误提示
    Vmware安装与VMware下Linux系统安装
    Git命令
    PHP--yii中findOne转换成数组
    Window上装PHP开发环境 (XAMPP)
    yii2.0框架中session与cookie的用法
    【网站架构】从简单到复杂,一步步演变
    nginx 配置反向代理,负载均衡实战解析
  • 原文地址:https://www.cnblogs.com/forever4444/p/1460374.html
Copyright © 2011-2022 走看看