HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)

并不是很精简,随便改改A过了就没有再简化了。

1020.

Problem Description

Given a string containing only ‘A‘ - ‘Z‘, we could encode it using the following method:

1. Each sub-string containing k same characters should be encoded to "kX" where "X" is the only character in this sub-string.

2. If the length of the sub-string is 1, ‘1‘ should be ignored.

Input

The first line contains an integer N (1 <= N <= 100) which indicates the number of test cases. The next N lines contain N strings. Each string consists of only ‘A‘ - ‘Z‘ and the length is less than 10000.

Output

For each test case, output the encoded string in a line.

Sample Input

2
ABC
ABBCCC

Sample Output

ABC
A2B3C

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,count;;
 7     cin>>n;
 8     while(n--)
 9     {
10         string str;
11         cin>>str;
12         for(int i=0;i<(int)str.length();i++)
13         {
14             count=1;
15             while(str[i]==str[i+1])
16             {
17                 count++;i++;
18             }
19             if(count!=1)
20                 cout<<count;
21             cout<<str[i];
22         }
23         cout<<endl;
24     }
25     return 0;
26 }

1020

1039.

Problem Description

Password security is a tricky thing. Users prefer simple passwords that are easy to remember (like buddy), but such passwords are often insecure. Some sites use random computer-generated passwords (like xvtpzyo), but users have a hard time remembering them and sometimes leave them written on notes stuck to their computer. One potential solution is to generate "pronounceable" passwords that are relatively secure but still easy to remember.

FnordCom is developing such a password generator. You work in the quality control department, and it‘s your job to test the generator and make sure that the passwords are acceptable. To be acceptable, a password must satisfy these three rules:

It must contain at least one vowel.

It cannot contain three consecutive vowels or three consecutive consonants.

It cannot contain two consecutive occurrences of the same letter, except for ‘ee‘ or ‘oo‘.

(For the purposes of this problem, the vowels are ‘a‘, ‘e‘, ‘i‘, ‘o‘, and ‘u‘; all other letters are consonants.) Note that these rules are not perfect; there are many common/pronounceable words that are not acceptable.

Input

The input consists of one or more potential passwords, one per line, followed by a line containing only the word ‘end‘ that signals the end of the file. Each password is at least one and at most twenty letters long and consists only of lowercase letters.

Output

For each password, output whether or not it is acceptable, using the precise format shown in the example.

Sample Input

a
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end

Sample Output

<a> is acceptable.
<tv> is not acceptable.
<ptoui> is not acceptable.
<bontres> is not acceptable.
<zoggax> is not acceptable.
<wiinq> is not acceptable.
<eep> is acceptable.
<houctuh> is acceptable.

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 bool search1(string str)
 5 {
 6     for(int i=0;i<=(int)str.length()-1;i++)
 7     {
 8         if(str[i]==‘a‘||str[i]==‘e‘)    return true;
 9         if(str[i]==‘i‘||str[i]==‘o‘||str[i]==‘u‘)    return true;
10     }
11     return false;
12 }
13 bool search2(string str)
14 {
15     int count1=0,count2=0;
16     for(int i=0;i<=(int)str.length()-1;i++)
17     {
18         if(i!=0&&str[i-1]==str[i])
19             {if(str[i]==‘o‘||str[i]==‘e‘);
20             else return false;}
21         if (str[i]==‘a‘||str[i]==‘e‘||str[i]==‘i‘||str[i]==‘o‘||str[i]==‘u‘)
22         {
23             count1++;
24             count2=0;
25         }
26         else
27         {
28             count2++;
29             count1=0;
30         }
31         if(count1>=3||count2>=3)
32             return false;
33     }
34     return true;
35 }
36 int main()
37 {
38     string str;
39     while(1)
40     {
41     cin>>str;
42     if(str=="end")
43         break;
44     if(search1(str)&&search2(str))
45         cout<<‘<‘<<str<<‘>‘<<" is acceptable."<<endl;
46     else
47         cout<<‘<‘<<str<<‘>‘<<" is not acceptable."<<endl;
48     }
49
50 }

1062.

Problem Description

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

Input

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output

For each test case, you should output the text which is processed.

Sample Input

3
olleh !dlrow
m‘I morf .udh
I ekil .mca

Sample Output

hello world!
I‘m from hdu.
I like acm.

Hint

Remember to use getchar() to read ‘\n‘ after the interger T, then you may use gets() to read a line and process it.

 1 #include<iostream>
 2 #include<string>
 3 using namespace std;
 4 const int maxn=1005;
 5 char a[maxn],b[maxn];
 6 void print(char *str)
 7 {
 8     for(int i=strlen(str)-1;i>=0;i--)
 9         cout<<str[i];
10 }
11 int main()
12 {
13     int n,i,j,len;
14     cin>>n;
15     getchar();
16     while(n--)
17     {
18         gets(a);
19         len=strlen(a);
20         a[len]=‘ ‘;
21         a[len+1]=‘\0‘;
22         b[0]=‘\0‘;
23         for(i=0,j=0;i<=len;i++)
24         {
25             if(a[i]==‘ ‘)
26             {
27                 print(b);
28                 b[0]=‘\0‘;
29                 cout<<(i==len?‘\n‘:‘ ‘);
30                 j=0;
31             }
32             else
33             {
34                 b[j]=a[i];
35                 j++;
36                 b[j]=‘\0‘;
37             }
38         }
39     }
40     return 0;
41 }

1088.

Problem Description

If you ever tried to read a html document on a Macintosh, you know how hard it is if no Netscape is installed. 
Now, who can forget to install a HTML browser? This is very easy because most of the times you don‘t need one on a MAC because there is a Acrobate Reader which is native to MAC. But if you ever need one, what do you do? 
Your task is to write a small html-browser. It should only display the content of the input-file and knows only the html commands (tags) <br> which is a linebreak and <hr> which is a horizontal ruler. Then you should treat all tabulators, spaces and newlines as one space and display the resulting text with no more than 80 characters on a line.

Input

The input consists of a text you should display. This text consists of words and HTML tags separated by one or more spaces, tabulators or newlines. 
A word is a sequence of letters, numbers and punctuation. For example, "abc,123" is one word, but "abc, 123" are two words, namely "abc," and "123". A word is always shorter than 81 characters and does not contain any ‘<‘ or ‘>‘. All HTML tags are either <br> or <hr>.

Output

You should display the the resulting text using this rules: 
  . If you read a word in the input and the resulting line does not get longer than 80 chars, print it, else print it on a new line. 
  . If you read a <br> in the input, start a new line. 
  . If you read a <hr> in the input, start a new line unless you already are at the beginning of a line, display 80 characters of ‘-‘ and start a new line (again). 
The last line is ended by a newline character.

Sample Input

Hallo, dies ist eine
ziemlich lange Zeile, die in Html
aber nicht umgebrochen wird.
<br>
Zwei <br> <br> produzieren zwei Newlines.
Es gibt auch noch das tag <hr> was einen Trenner darstellt.
Zwei <hr> <hr> produzieren zwei Horizontal Rulers.
Achtung mehrere Leerzeichen irritieren

Html genauso wenig wie

mehrere Leerzeilen.

Sample Output

Hallo, dies ist eine ziemlich lange Zeile, die in Html aber nicht umgebrochen
wird.
Zwei

produzieren zwei Newlines. Es gibt auch noch das tag
--------------------------------------------------------------------------------
was einen Trenner darstellt. Zwei
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
produzieren zwei Horizontal Rulers. Achtung mehrere Leerzeichen irritieren Html
genauso wenig wie mehrere Leerzeilen.

 1 #include<iostream>
 2 char s[10000];
 3 using namespace std;
 4 int main()
 5 {
 6     int count=0;
 7     while(~scanf("%s",s))
 8     {
 9         if(!strcmp(s,"<br>"))
10         {
11             cout<<endl;
12             count=0;
13         }
14         else if(!strcmp(s,"<hr>"))
15         {
16             if(count)
17                 cout<<‘\n‘;
18             cout<<"--------------------------------------------------------------------------------\n";
19             count=0;
20         }
21         else
22         {
23             int length=strlen(s);
24             if(count==0)
25             {
26                 cout<<s;
27                 count=length;
28             }
29             else if((count+length+1)>=80)
30                 {
31                     cout<<endl<<s;
32                     count=length;
33                 }
34                  else
35                  {
36                     cout<<‘ ‘<<s;
37                     count+=length+1;
38                  }
39         }
40     }
41     cout<<endl;
42 }

1161.

Problem Description

Eddy usually writes articles ,but he likes mixing the English letter uses, for example "computer science" is written frequently "coMpUtEr scIeNce" by him, this mistakes lets Eddy‘s English teacher be extremely discontentment.Now please you to write a procedure to be able in the Bob article English letter to turn completely the small letter.

Input

The input contains several test cases.each line consists a test case,Expressed Eddy writes in an article , by letter, blank space,numeral as well as each kind of punctuation
composition, the writing length does not surpass 1000 characters.

Output

For each test case, you should output an only line, after namely the result of transforms the lowercase letter.

Sample Input

weLcOmE tO HDOj Acm 2005!

Sample Output

welcome to hdoj acm 2005!

 1 #include<iostream>
 2 const int maxn=1005;
 3 char str[1005];
 4 using namespace std;
 5 int  main()
 6 {
 7     while(gets(str))
 8     {
 9         for(int i=0;str[i]!=‘\0‘;i++)
10         {
11             if(str[i]>=‘A‘&&str[i]<=‘Z‘)
12                 str[i]+=32;
13         }
14         cout<<str<<endl;
15     }
16 }

1200.

Problem Description

Mo and Larry have devised a way of encrypting messages. They first decide secretly on the number of columns and write the message (letters only) down the columns, padding with extra random letters so as to make a rectangular array of letters. For example, if the message is “There’s no place like home on a snowy night” and there are five columns, Mo would write down

t o i o y
h p k n n
e l e a i
r a h s g
e c o n h
s e m o t
n l e w x

Note that Mo includes only letters and writes them all in lower case. In this example, Mo used the character ‘x’ to pad the message out to make a rectangle, although he could have used any letter.

Mo then sends the message to Larry by writing the letters in each row, alternating left-to-right and right-to-left. So, the above would be encrypted as

toioynnkpheleaigshareconhtomesnlewx

Your job is to recover for Larry the original message (along with any extra padding letters) from the encrypted one.

Input

There will be multiple input sets. Input for each set will consist of two lines. The first line will contain an integer in the range 2. . . 20 indicating the number of columns used. The next line is a string of up to 200 lower case letters. The last input set is followed by a line containing a single 0, indicating end of input.

Output

Each input set should generate one line of output, giving the original plaintext message, with no spaces.

Sample Input

5
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0

Sample Output

theresnoplacelikehomeonasnowynightx

thisistheeasyoneab

 1 #include<iostream>
 2 using namespace    std;
 3 #include<string>
 4 int main()
 5 {
 6         // freopen("F:\\in.txt","r",stdin);
 7     //freopen("F:\\ou.txt","w",stdout);
 8     string s;int c,t,count;
 9     while(1){
10     cin>>c;
11     if(!c) break;
12     cin>>s;
13     int n=int(s.length());
14     for(int k=1;k<=c;k++)
15     {
16         t=k-1;count=1;
17         while(t<=n-1)
18         {
19             cout<<s[t];
20             if(count%2)
21                 t+=2*c-1-2*(k-1);
22             else
23                 t+=2*k-1;
24             count++;
25         }
26     }
27     cout<<endl;
28     }
29     //fclose(stdin);
30     //fclose(stdout);
31     return 0;
32 }

2017.

Problem Description

对于给定的一个字符串,统计其中数字字符出现的次数。

Input

输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。

Output

对于每个测试实例,输出该串中数值的个数,每个输出占一行。

Sample Input

2
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf

Sample Output

6
9

 1 #include<iostream>
 2 #include<cctype>
 3 #include<string>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,count;
 8     cin>>n;
 9     while(n--)
10     {
11         count=0;
12         string str;
13         cin>>str;
14         for(string::iterator it=str.begin();it!=str.end();it++)
15             if(isdigit(*it))
16                 count++;
17         cout<<count<<endl;
18     }
19
20 }

时间: 2024-08-07 14:54:43

HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)的相关文章

hdu 5326(基础题) work

http://acm.hdu.edu.cn/showproblem.php?pid=5326 一道水题,题目大意是在公司里,给出n个员工和目标人数m,然后下面的n-1行是表示员工a管理b,问在这些员工中有多少管理员工的人数是k 起初想的是并查集,后来发现没那么简单,因为两者之间的关系有方向的,a管理b是单向的从b指到a,所以并查集的一个集合里包含了很多种关系 还需要用一个二维数组表示关系,它是一环扣一环的从a找到b再从b找到c......因为如果b管理c,a又管理b,那么a也管理c code 1

HDU 2966 Aragorn&#39;s Story 树链剖分第一题 基础题

Problem Description Our protagonist is the handsome human prince Aragorn comes from The Lord of the Rings. One day Aragorn finds a lot of enemies who want to invade his kingdom. As Aragorn knows, the enemy has N camps out of his kingdom and M edges c

Print Article hdu 3507 一道斜率优化DP 表示是基础题,但对我来说很难

Print Article Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 4990    Accepted Submission(s): 1509 Problem Description Zero has an old printer that doesn't work well sometimes. As it is antique

hdu 5007(字符串水题)

题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5007 Post Robot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 327    Accepted Submission(s): 253 Problem Description DT is a big fan of digital

Jam&#39;s balance HDU - 5616 (01背包基础题)

Jim has a balance and N weights. (1≤N≤20) The balance can only tell whether things on different side are the same weight. Weights can be put on left side or right side arbitrarily. Please tell whether the balance can measure an object of weight M. In

1、基础题

基础题: 1.表单中 get与post提交方法的区别? 答:get是发送请求HTTP协议通过url参数传递进行接收,而post是实体数据,可以通过表单提交大量信息. 2.session与cookie的区别? 答:session:储存用户访问的全局唯一变量,存储在服务器上的php指定的目录中的(session_dir)的位置进行的存放 cookie:用来存储连续訪問一个頁面时所使用,是存储在客户端,对于Cookie来说是存储在用户WIN的Temp目录中的. 两者都可通过时间来设置时间长短 3.数据

一些DP基础题(1)

HDU 1024  Max Sum Plus Plus Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem. Given a consecutive num

nyist oj 36 最长公共子序列 (动态规划基础题)

最长公共子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列. tip:最长公共子序列也称作最长公共子串(不要求连续),英文缩写为LCS(Longest Common Subsequence).其定义是,一个序列 S ,如果分别是两个或多个已知序列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列. 输入 第一行给出一个整数N(0<N<100)表示待测数据组数 接

小试牛刀3之JavaScript基础题

JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: 如果用户单击提示框的取消按钮,则返回 null.如果用户单击确认按钮,则返回输入字段当前显示的文本. 在用户点击确定按钮或取消按钮把对话框关闭之前,它将阻止用户对浏览器的所有输入.在调用 prompt() 时,将暂停对 JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句. *