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;
    }
  • 相关阅读:
    深入理解Kafka-学习笔记04-部分生产者客户端参数
    深入理解Kafka-学习笔记03-消息有序性
    IDEA包不存在找不到包解决方案
    深入理解Kafka-学习笔记02-生产者整体架构
    深入理解Kafka-学习笔记01-初识Kafka
    ClickHouse与MySQL数据类型对应
    MySQL查看版本
    从apache phoenix表提取数据为CSV
    Kafka查看版本
    HBASE查看版本
  • 原文地址:https://www.cnblogs.com/forever4444/p/1460374.html
Copyright © 2011-2022 走看看