zoukankan      html  css  js  c++  java
  • 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 }
    View Code

    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 ' ' 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]='';
    22         b[0]='';
    23         for(i=0,j=0;i<=len;i++)
    24         {
    25             if(a[i]==' ')
    26             {
    27                 print(b);
    28                 b[0]='';
    29                 cout<<(i==len?'
    ':' ');
    30                 j=0;
    31             }
    32             else
    33             {
    34                 b[j]=a[i];
    35                 j++;
    36                 b[j]='';
    37             }
    38         }
    39     }
    40     return 0;
    41 }
    View Code

    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<<'
    ';
    18             cout<<"--------------------------------------------------------------------------------
    ";
    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 }
    View Code

    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]!='';i++)
    10         {
    11             if(str[i]>='A'&&str[i]<='Z')
    12                 str[i]+=32;
    13         }
    14         cout<<str<<endl;
    15     }
    16 }
    View Code

    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 }
    View Code

    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 }
    View Code
     
  • 相关阅读:
    SpringBoot自定义错误页面,SpringBoot 404、500错误提示页面
    SpringBoot切换Tomcat容器,SpringBoot使用Jetty容器
    SpringBoot 国际化配置,SpringBoot Locale 国际化
    SpringBoot Logback配置,SpringBoot日志配置
    SpringBoot thymeleaf使用方法,thymeleaf模板迭代
    SpringBoot thymeleaf模板页面没提示,SpringBoot thymeleaf模板插件安装
    JSP判断闰年
    JSP求和计算
    JSP指令
    jsp新建项目
  • 原文地址:https://www.cnblogs.com/ljwTiey/p/4273529.html
Copyright © 2011-2022 走看看