寒假作业,2.25,G - iBoard

Posted ineedyou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了寒假作业,2.25,G - iBoard相关的知识,希望对你有一定的参考价值。

题目:

技术分享图片

 

After years of success with a single-button mouse, a well known computer company has decided to offer a similarly simplified interface for the keyboard. The iBoard has only two keys. The user types by entering the ASCII code for each letter. To help people type faster, the iBoard uses key press and key release transitions to enter characters. Pressing or releasing the right key enters zero for the next bit. Pressing or releasing the left key enters a one. The binary code for each 7-bit ASCII character is entered starting with the least significant bit and working up to the most significant bit. For example, to type a capital Z, the user simply has to press the right key, press the left key, release the right key, release the left key, press the left key, press the right key and then release the left key.

Although its creators would like you to believe that the iBoard is far superior to any other keyboard, it does have one disadvantage. The operator may not be free to get up and go to the bathroom as soon as he or she needs to. After typing a string of characters, the user may be stuck with one or more fingers pressing iBoard keys. Releasing these keys would begin typing the next character. Your job is to write a program that determines when it’s safe to get up and leave the keyboard. Your program should read input strings and report if it’s safe to get up and leave the iBoard after typing each string.

Input

Input contains up to 100 strings, one per line, terminated at end of file. Each string has between 1 and 100 ASCII characters. End-of-line characters should not be considered part of each string.

Output

For each input string, print out a line reporting either trapped or free. The user is considered trapped if one or more iBoard keys is still being pressed after the string is typed. Otherwise, the user is free. You should assume that no iBoard keys are being pressed when the user starts typing the string.

Sample Input 1Sample Output 1
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<cstdlib>
#include<ctype.h>
using namespace std;
typedef long long ll;
#define pi 3.14159265358979323846264338327
#define E 2.71828182846
#define INF 0x3f3f3f3f
#define maxn 555555
#define lcm 21252

#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int a[7];
int main()
{
	string s;
	while(getline(cin,s))
	{
		bool left=0,right=0;
		for(int i=0;i<s.size();i++)
		{
			memset(a,0,sizeof(a));\\\\下为二进制
			int temp=(int)s[i];
			int c=0;
			while(temp>1)
			{
				a[c++]=temp%2;
				temp/=2;
			}
			if(temp)a[6]=1;
			else a[6]=0;
			for(int j=0;j<7;j++)
			{
				if(a[j])
				{
					if(left)
						left=0;
					else
						left=1;
				}else
				{
					if(right)
						right=0;
					else
						right=1;
				}
			}
		}
		if(right||left)printf("trapped\\n");
		else	printf("free\\n");
	}
	return 0;
}

  

trapped
free
trapped

 

以上是关于寒假作业,2.25,G - iBoard的主要内容,如果未能解决你的问题,请参考以下文章

寒假作业3

2017级面向对象程序设计寒假作业第2次成绩排行

寒假作业03

寒假作业总结

寒假作业2 电梯问题

寒假作业2