F. Set the memory

F. Set the memory

Time Limit: 1000ms
Memory Limit: 65536KB
64-bit integer IO format: %lld      Java class name: Main

You have been given a very strange computer. Its memory consists of several bits, each initially set to 0, and it can perform only one type of operation: Choose one of the bits in memory, and choose a value - 0 or 1. All the bits between the selected bit and the last bit in memory, inclusive, will be set to the chosen value. For example, if the memory is "0010", and you choose the second bit and a value of 1, the memory will change to "0111". You are given a string s. The number of characters in s is equal to the number of bits in the computer's memory. calculate the minimum number of operations required to set the computer's memory equal to s.

Input

Only one line : the string s
s will contain between 1 and 10,000 characters, inclusive.
s will contain only the characters '0' (zero) or '1' (one).

 

请使用scanf("%s")读入

 

Output

minimum number of operations required to set the computer's memory equal to s.

Sample Input

0100

Sample Output

2

Hint

The operations of the Sample:
0000 -> 0111 -> 0100




#include<stdio.h>
#include<string.h>
int main()
{
    char a[100000];
    int l,i,j;
    while(scanf("%s",a)!=-1)
    {
        int h;
        l=strlen(a);
        for(i=0; i<l; i++)
        {
            if(a[i]=='1')
            {
                h=i;
                break;
            }
        }
        int k=0;
        for(i=h; i<l; i++)//前面和后边不一样就加一
        {
            if(a[i]!=a[i+1])
            {
                k++;
            }
        }
        printf("%d\n",k);
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Write a program to 1.Setup a simulating backing store in memory. Read the data from pdata.bin to this backing store. 2.Initialize a page table for process p, set the frame number to be -1 for each page, indicating that the page is not loaded into memory yet. 3.Read logical addresses one by one from la.txt. 4.For each logical address, a)if its page has been loaded into physical memory, simply find the frame number in the page table, then generate physical address, find and print out the physical address and data inside this address. b)if the page is used for the first time, i.e., in page table, its frame number is -1,then the page that contains this address should be loaded into a free frame in physical memory (RAM). Then update the page table by adding the frame number to the right index in the page table. Then repeat 4a). Assumption: 1.Assume the file la.txt includes the sequence of generated addresses from CPU. 2.Use a part of memory as backing store that store data for a process. 3.The backing store size is 128 bytes 4.The size of process p is 128 bytes. 5.The contents of p is included in a file pdata.bin which is a binary file. 6.Use a part of memory as RAM. The size of physical memory is 256 bytes, from 0 to 255. All the physical memory is available, allocating starting from beginning in sequence. That is, allocate frame 0 first, then frame 1, then frame 2…. 7.The size of a frame is 32 bytes, i.e., 5 bits for the offset in a frame, total number of frames is 8. At beginning, no page table is available for process p.
05-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值