上海交通大学

上海交通大学机试题——后缀字串排序(C++)

不羁的心 提交于 2020-03-02 15:03:18
题目描述 Time Limit: 1000 ms Memory Limit: 256 mb 对于一个字符串,将其后缀子串进行排序,例如grain 其子串有: grain rain ain in n 然后对各子串按字典顺序排序,即: ain,grain,in,n,rain 输入输出格式 输入描述: 每个案例为一行字符串。 输出描述: 将子串排序输出 输入样例: grain 输出样例: ain grain in n rain #include<iostream> #include<string> #include<string.h> #include<algorithm> using namespace std; int main(){ char s[105]; cin>>s; int count = strlen(s);//获取长度 string t[count]; for(int i = 0; s[i] != '\0'; i++){ for(int j = i; s[j] != '\0'; j++){ t[i] = t[i]+s[j]; }//把所有后缀依次求出放入t数组 } sort(t,t+count);//按照字典序排序 for(int i = 0; i < count; i++){ cout<<t[i]<<endl; } return 0; } 来源: CSDN 作者:

上海交通大学 数字反转(java)

旧时模样 提交于 2020-02-06 00:44:52
题目描述 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转。 输入描述: 每行两个正整数a和b(0<a,b<=10000)。 输出描述: 如果满足题目的要求输出a+b的值,否则输出NO。 示例1 输入 复制 2 12 34 99 1 输出 复制 46 NO import java . io . * ; import java . util . * ; public class Main { public static void main ( String [ ] args ) { try { BufferedReader br = new BufferedReader ( new InputStreamReader ( System . in ) ) ; String [ ] parts = br . readLine ( ) . split ( " " ) ; StringBuilder a = new StringBuilder ( parts [ 0 ] ) ; StringBuilder b = new StringBuilder ( parts [ 1 ] ) ; int sum = Integer . parseInt ( a . toString ( ) ) + Integer

上海交通大学 Zero-complexity Transposition(java)

♀尐吖头ヾ 提交于 2020-02-05 21:52:26
题目描述 You are given a sequence of integer numbers. Zero-complexity transposition of the sequence is the reverse of this sequence. Your task is to write a program that prints zero-complexity transposition of the given sequence. 输入描述: For each case, the first line of the input file contains one integer n-length of the sequence (0 < n ≤ 10 000). The second line contains n integers numbers-a1, a2, …, an (-1 000 000 000 000 000 ≤ ai ≤ 1 000 000 000 000 000). 输出描述: For each case, on the first line of the output file print the sequence in the reverse order. 示例1 输入 复制 5 -3 4 6 -8 9 输出 复制 9 -8 6 4 -3

上海交通大学 WERTYU(java)

社会主义新天地 提交于 2020-02-05 01:29:07
题目描述 A common typing error is to place the hands on the keyboard one row to the right of the correct position. So "Q" is typed as "W" and "J" is typed as "K" and so on. You are to decode a message typed in this manner. 输入描述: Input consists of several lines of text. Each line may contain digits, spaces, upper case letters (except Q, A, Z), or punctuation shown above [except back-quote (`)]. Keys labelled with words [Tab, BackSp, Control, etc.] are not represented in the input. 输出描述: You are to replace each letter or punctuation symbol by the one immediately to its left on the QWERTY keyboard