string的特殊用法

string   a=12

string  b=34

a+b=1234      b+a=3412

 

Children's Game
Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu

 

Description

Download as PDF

4thIIUCInter-University Programming Contest, 2005

A

Children’s Game

Input: standard input
Output: standard output

Problemsetter: Md. Kamruzzaman

There are lots of number games for children. These games are pretty easy to play but not so easy to make. We will discuss about an interesting game here. Each player will be given N positive integer. (S)He can make a big integer by appending those integers after one another. Such as if there are 4 integers as 123, 124, 56, 90 then the following integers can be made – 1231245690, 1241235690, 5612312490, 9012312456, 9056124123 etc. In fact 24 such integers can be made. But one thing is sure that 9056124123 is the largest possible integer which can be made.

You may think that it’s very easy to find out the answer but will it be easy for a child who has just got the idea of number?

Input

Each input starts with a positive integer N (≤ 50). In next lines there are N positive integers. Input is terminated by N = 0, which should not be processed.

Output

For each input set, you have to print the largest possible integer which can be made by appending all the N integers.

Sample Input

Output for Sample Input

4
123 124 56 90
5
123 124 56 90 9
5
9 9 9 9 9
0

9056124123
99056124123
99999

 

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string>
using namespace std;

bool cmp(string a,string b)
{
 return a+b>b+a;
}

int main()
{
 int n;
 string w[55];
 while(cin>>n)
 {
  if(n==0) break;
  int i;
  for(i=0;i<n;i++)
  {
   cin>>w[i];
  }
  sort(w,w+n,cmp);
  for(i=0;i<n;i++)
  {
   cout<<w[i];
  }
  cout<<endl;
 }
 return 0;
}


 

### String 数据类型概述 在不同编程语言中,`String` 的实现方式和特性有所不同。以下是几种常见编程语言中 `String` 类型的介绍及其使用方法。 #### Java 中的 String Java 将 `String` 设计为一个不可变的对象,表示字符序列[^3]。由于其不可变性,在每次对字符串进行操作时都会创建新的实例。这使得频繁修改字符串的应用场景下性能较低效;此时推荐使用 `StringBuilder` 或者 `StringBuffer` 来替代。 ```java // 创建字符串对象 String greeting = "Hello, world!"; System.out.println(greeting); // 连接两个字符串 String name = "Alice"; String message = greeting + ", my name is " + name; System.out.println(message); ``` #### C 语言中的字符串处理 不同于其他高级语言,C 并未提供专门用于表示字符串的数据类型,而是通过字符数组来模拟这一功能[^2]。每个有效的字符串都由若干个 ASCII 编码构成,并且最后一个有效字符后面紧跟着一个特殊的终止符 `\0` 表明结束位置。 ```c #include <stdio.h> int main() { char str[] = {'H', 'e', 'l', 'l', 'o', '\0'}; printf("%s\n", str); // 输出 Hello const char *strPtr = "World"; printf("Greeting: %s\n", strPtr); // 输出 Greeting: World } ``` #### Python 中的字符串基础 Python 把 `str` 当作一种内置数据类型对待,支持多种编码格式(默认 UTF-8),并且提供了丰富的内置函数来进行各种各样的转换与查询工作。值得注意的是,同 Java 一样,Python 下定义好的字符串也是只读属性。 ```python text = "This is a sample text." print(text.upper()) # 转换成大写形式 THIS IS A SAMPLE TEXT. print(len(text)) # 获取长度 21 print(text.split(' ')) # 切分成列表 ['This', 'is', 'a', 'sample', 'text.'] ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值