HDU字符串基础题(1020,1039,1062,1088,1161,1200,2017)
并不是很精简,随便改改A过了就没有再简化了。
1020.
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.
ABC
ABBCCC
A2B3C
#include<iostream>
#include<string>
using namespace std;
int main()
{
int n,count;;
cin>>n;
while(n--)
{
string str;
cin>>str;
for(int i=;i<(int)str.length();i++)
{
count=;
while(str[i]==str[i+])
{
count++;i++;
}
if(count!=)
cout<<count;
cout<<str[i];
}
cout<<endl;
}
return ;
}
1020
1039.
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.
tv
ptoui
bontres
zoggax
wiinq
eep
houctuh
end
<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.
#include<iostream>
#include<string>
using namespace std;
bool search1(string str)
{
for(int i=;i<=(int)str.length()-;i++)
{
if(str[i]=='a'||str[i]=='e') return true;
if(str[i]=='i'||str[i]=='o'||str[i]=='u') return true;
}
return false;
}
bool search2(string str)
{
int count1=,count2=;
for(int i=;i<=(int)str.length()-;i++)
{
if(i!=&&str[i-]==str[i])
{if(str[i]=='o'||str[i]=='e');
else return false;}
if (str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
{
count1++;
count2=;
}
else
{
count2++;
count1=;
}
if(count1>=||count2>=)
return false;
}
return true;
}
int main()
{
string str;
while()
{
cin>>str;
if(str=="end")
break;
if(search1(str)&&search2(str))
cout<<'<'<<str<<'>'<<" is acceptable."<<endl;
else
cout<<'<'<<str<<'>'<<" is not acceptable."<<endl;
} }
1062.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
olleh !dlrow
m'I morf .udh
I ekil .mca
I'm from hdu.
I like acm.
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
#include<iostream>
#include<string>
using namespace std;
const int maxn=;
char a[maxn],b[maxn];
void print(char *str)
{
for(int i=strlen(str)-;i>=;i--)
cout<<str[i];
}
int main()
{
int n,i,j,len;
cin>>n;
getchar();
while(n--)
{
gets(a);
len=strlen(a);
a[len]=' ';
a[len+]='\0';
b[]='\0';
for(i=,j=;i<=len;i++)
{
if(a[i]==' ')
{
print(b);
b[]='\0';
cout<<(i==len?'\n':' ');
j=;
}
else
{
b[j]=a[i];
j++;
b[j]='\0';
}
}
}
return ;
}
1088.
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.
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>.
. 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.
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.
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.
#include<iostream>
char s[];
using namespace std;
int main()
{
int count=;
while(~scanf("%s",s))
{
if(!strcmp(s,"<br>"))
{
cout<<endl;
count=;
}
else if(!strcmp(s,"<hr>"))
{
if(count)
cout<<'\n';
cout<<"--------------------------------------------------------------------------------\n";
count=;
}
else
{
int length=strlen(s);
if(count==)
{
cout<<s;
count=length;
}
else if((count+length+)>=)
{
cout<<endl<<s;
count=length;
}
else
{
cout<<' '<<s;
count+=length+;
}
}
}
cout<<endl;
}
1161.
composition, the writing length does not surpass 1000 characters.
#include<iostream>
const int maxn=;
char str[];
using namespace std;
int main()
{
while(gets(str))
{
for(int i=;str[i]!='\0';i++)
{
if(str[i]>='A'&&str[i]<='Z')
str[i]+=;
}
cout<<str<<endl;
}
}
1200.
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.
toioynnkpheleaigshareconhtomesnlewx
3
ttyohhieneesiaabss
0
#include<iostream>
using namespace std;
#include<string>
int main()
{
// freopen("F:\\in.txt","r",stdin);
//freopen("F:\\ou.txt","w",stdout);
string s;int c,t,count;
while(){
cin>>c;
if(!c) break;
cin>>s;
int n=int(s.length());
for(int k=;k<=c;k++)
{
t=k-;count=;
while(t<=n-)
{
cout<<s[t];
if(count%)
t+=*c--*(k-);
else
t+=*k-;
count++;
}
}
cout<<endl;
}
//fclose(stdin);
//fclose(stdout);
return ;
}
2017.
asdfasdf123123asdfasdf
asdf111111111asdfasdfasdf
9
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
int main()
{
int n,count;
cin>>n;
while(n--)
{
count=;
string str;
cin>>str;
for(string::iterator it=str.begin();it!=str.end();it++)
if(isdigit(*it))
count++;
cout<<count<<endl;
} }
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,问在这些员工 ...
- HDU 1301 Jungle Roads (最小生成树,基础题,模版解释)——同 poj 1251 Jungle Roads
双向边,基础题,最小生成树 题目 同题目 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include<stri ...
- hdu 2089 不要62 (数位dp基础题)
不要62 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Jam'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 ...
- 小试牛刀3之JavaScript基础题
JavaScript基础题 1.让用户输入两个数字,然后输出相加的结果. *prompt() 方法用于显示可提示用户进行输入的对话框. 语法: prompt(text,defaultText) 说明: ...
- 小试牛刀2:JavaScript基础题
JavaScript基础题 1.网页中有个字符串“我有一个梦想”,使用JavaScript获取该字符串的长度,同时输出字符串最后两个字. 答案: <!DOCTYPE html PUBLIC &q ...
- POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划)
POJ 2342 Anniversary party / HDU 1520 Anniversary party / URAL 1039 Anniversary party(树型动态规划) Descri ...
- Java面试题以及答案精选(架构师面试题)-基础题1
基础题 一.String,StringBuffer, StringBuilder 的区别是什么?String为什么是不可变的?1. String是字符串常量,StringBuffer和StringBu ...
- C/C++笔试题(基础题)
为了便于温故而知新,特于此整理 C/C++ 方面相关面试题.分享,共勉. (备注:各题的重要程度与先后顺序无关.不断更新中......欢迎补充) (1)分析下面程序的输出(* 与 -- 运算符优先级问 ...
随机推荐
- mongodb取出最大值与最小值
$res=self::aggregate([ ['$match'=>[ 'msg_id'=>1007, 'D'=>16, ]], ['$group'=>[ '_id'=> ...
- [leetcode-630-Course Schedule III]
There are n different online courses numbered from 1 to n. Each course has some duration(course leng ...
- spring的Convert机制
spring.core包内有Converter接口,方法是T convert(S source);从一个类型转为内容一个类型的实际转化器:converters可能非常多,需要一个注册器来集中管理使用, ...
- 详解ASP.NET MVC 控制器
1 概述 在阅读本篇博文时,建议结合上篇博文:详解ASP.NET MVC 路由 一起阅读,效果可能会更好些. Controller(控制器)在ASP.NET MVC中负责控制所有客户端与服务端的 ...
- Azure SQL Database (23) Azure SQL Database Dynamic Data Masking动态数据掩码
<Windows Azure Platform 系列文章目录> 我们在使用关系型数据的时候,有时候希望: - 管理员admin,可以查看到所有的数据 - 普通用户,某些敏感字段,比如信用卡 ...
- Bootstrap警告框
前面的话 在网站中,网页总是需要和用户一起做沟通与交流.特别是当用户操作上下文为用户提供一些有效的警示框,比如说告诉用户操作成功.操作错误.提示或者警告等.在Bootstrap框架有一个独立的组件,实 ...
- Linux 多用户系统
Linux OS是基于Unix系统开发而来,我们知道计算机是昂贵与稀缺的资源,所以一台计算机就要满足多个用户同时使用,即多用户的系统的思想. 实现方式:通过分时共享的策略.即让多个用户可以同时使用一台 ...
- 数据结构3——浅谈zkw线段树
线段树是所有数据结构中,最常用的之一.线段树的功能多样,既可以代替树状数组完成"区间和"查询,也可以完成一些所谓"动态RMQ"(可修改的区间最值问题)的操作.其 ...
- js中嵌入jsp(html)代码的双引号转换问题--事件没反应
下面是一段今天遇到问题的代码,select中写了onchange事件 ,在没有加转义的情况下,F12解析的代码是错乱的,双引号与内容中写的不一致,还会有空格出现,经过一段时间的摸索,发现在出错的地方加 ...
- JAVA实用案例之水印开发
写在最前面 上周零零碎碎花了一周的时间研究水印的开发,现在终于写了个入门级的Demo,做下笔记同时分享出来供大家参考. Demo是在我上次写的 JAVA实用案例之文件导入导出(POI方式) 框架基础上 ...