zoukankan      html  css  js  c++  java
  • 按顺序输出字符串问题

    问题:

    Input
     
    The input consists of one or more sets of strings, followed by a final line containing only the value 0. Each set starts with a line containing an integer, n, which is the number of strings in the set, followed by n strings, one per line, sorted in nondescending order by length. None of the strings contain spaces. There is at least one and no more than 15 strings per set. Each string is at most 25 characters long.
    Output
     
    For each input set print "SET n" on a line, where n starts at 1, followed by the output set as shown in the sample output.
    Sample Input
     
    7
    Bo
    Pat
    Jean
    Kevin
    Claude
    William
    Marybeth
    6
    Jim
    Ben
    Zoe
    Joey
    Frederick
    Annabelle
    5
    John
    Bill
    Fran
    Stan
    Cece
    0
    Sample Output
     
    SET 1
    Bo
    Jean
    Claude
    Marybeth
    William
    Kevin
    Pat
    SET 2
    Jim
    Zoe
    Frederick
    Annabelle
    Joey
    Ben
    SET 3
    John
    Fran
    Cece
    Stan
    Bill
     
    回答:
    #include <iostream>
    #include <string>
    using namespace std;
    int main()
    {
    int n, t = 0, i, j, k;
    string word1[16], word2[16];
    while(cin >> n && n){
       j = k = 0;
       for(i=0; i<n; i++)
        cin >> word1[i];
       for(i=0; i<n; i++)
      if(i%2==0){
      word2[j] = word1[i];
      j++;
      }
      else {
      word2[n-k-1] = word1[i];
      k++;
      }
       cout << "SET " << ++t << endl;
       for(i=0; i<n; i++)
        cout << word2[i] << endl;
    }
        return 0;
    }
  • 相关阅读:
    什么是静态测试、动态测试、黑盒测试、白盒测试、α测试 β测试
    软件产品质量特性
    目前主要的测试用例设计方法是什么?
    软件的安全性应从哪几个方面去测试?
    软件配置管理的作用?软件配置包括什么?
    HDOJ1003(DP)
    HDOJ5650
    POJ1068(模拟)
    POJ2586(贪心)
    HDOJ1548(BFS)
  • 原文地址:https://www.cnblogs.com/benchao/p/4496481.html
Copyright © 2011-2022 走看看