1094. E-screen
Time limit: 0.25 second
Memory limit: 64 MB
Memory limit: 64 MB
A new one-line electronic screen (e-screen) especially designed for quick input and change of information was installed at a supermarket. All information is entered by an operator. Every time the operator presses a button corresponding to a symbol this symbol is shown on the e-screen at the position where the cursor is located at that moment (therefore the symbol that was shown at that position earlier is erased) and then the cursor moves one position to the right.
The keyboard contains letters a-z, A-Z, digits 0-9, punctuation signs (:;-!?.,), and the space button. There are also two keys that move the cursor one position to the right and to the left without erasing anything. The width of the screen is 80 symbols. When the cursor reaches left or right edge of the screen it is automatically placed at the first position to the left.
The new e-screen had worked perfectly when it was run by its seller, but when the seller had gone it was found that nobody could operate the e-screen properly. Besides, the e-screen was installed in such a place that the operator could not see it. Your task is to make a program emulation of the e-screen so that the operator could see the results of his or her actions.
Input
The single line of the input contains a sequence of the buttons pressed by the operator. The symbol '>' stands for the move of the cursor one position to the right and the symbol '<' stands for the move of the cursor one position to the left. There are no more than 10000 symbols at the input.
Output
The output should contain the line that would be shown on the e-screen after pressing the given sequence of the buttons. Assume that at the beginning the e-screen contains 80 spaces and the cursor is placed at the first position to the left.
Sample
input |
---|
>><<<Look for clothes at the <<<<<<<<<<<<<<<second flo or. <<<<<<<Fresh pizza and <<<<<<<<<<<<<<<<hamburger a t a shop right to <<<<<<<<<<<<<the entrance. Call <<<< <<<<<< 123<-456<-8790 <<<<<<<<<<<<<<<<to order <<<<<<< <<<<<<<<<<computers< and office<<<<<<< chairs. |
output |
Look for second hamburger at computer and chairs.790 |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char ch[10005];
char ans[85];
int main()
{
// freopen("q.in","r",stdin);
int i,j=0,len;
memset(ans,' ',sizeof(ans));
while(gets(ch))
{
len=strlen(ch);
for(i=0;i<len;i++)
{
if(ch[i]=='<')
{
j--;
if(j==-1)j=0;
}
else if(ch[i]=='>')
{
j++;
if(j==80)j=0;
}
else
{
ans[j++]=ch[i]; //这里不能直接取余,而是变成0
if(j==80)j=0;
}
}
}
for(i=0;i<80;i++)
printf("%c",ans[i]);
printf("\n");
}
1038. Spell Checker
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
The boss of a firm that you are employed with is dissatisfied with the text processor Word. He wants you to write a better text processor by tomorrow. The interface of the new processor should be clearer, there should be more options, and the resulting text should be more beautiful. You told the boss that this work would take not less than four days. Then your boss asked you to begin with a spell checking program. This program should check capital and small letters. It should detect a mistake in each of the following cases.
- The first letter in a sentence is small.
- A capital letter is not the first letter in a word.
A word is a sequence of letters not containing any other symbols or ends of line.
The end of a sentence is defined a full stop, a question-mark or an exclamation mark.
Input
Input contains a text that consists of capital and small letters of the Latin alphabet (A–Z, a–z), digits (0–9), punctuation marks (.,;:-!?) and space characters. The text length is not more than 10000.
Output
Output should contain a number of mistakes in the input text.
Sample
input | output |
---|---|
This sentence iz correkt! -It Has,No mista;.Kes et oll. But there are two BIG mistakes in this one! and here is one more. | 3 |
话说这还和AC自动机的原理扯上边了,但是听说自动机很难,渣渣还没学。。。用一个变量over标示状态,over==0,表示处于单词状态,over==1表示处于句首状态,分别判断字母是否符合规定就好,其他字符直接略过。
#include<iostream>
#include<cstdio>
#include<cctype>
#include<cstring>
using namespace std; //原来审题出错啦。。。。o(╯□╰)o
int main()
{
freopen("q.in","r",stdin);
int i,j,res=0;
char ch;
bool over=true;//over=1,表示处于单词结束状态,over=0 表示处于单词状态
while((ch=getchar())!=EOF)
{
if(ch=='.' || ch=='?' || ch=='!')
{
over=true;
// cout<<"......"<<endl;
continue;
}
if(!isalpha(ch))continue;
if(over && !isupper(ch)) //判断句首是否是小写错误了
{
res++;
// cout<<ch<<endl;
}
over=false;
ch=getchar();
while(isalpha(ch))
{
if(isupper(ch))
{
res++;
cout<<ch<<endl;
}
ch=getchar();
}
if(ch=='.' || ch=='?' || ch=='!')over=true;
}
cout<<res<<endl;
}