Try reading the thread more carefully.jddantes wrote:What's wrong with mine?
There is a blank line after every set of output. However, as mentioned several times before, there is no blank line after the last set of output.
Moderator: Board moderators
Try reading the thread more carefully.jddantes wrote:What's wrong with mine?
There is a blank line after every set of output. However, as mentioned several times before, there is no blank line after the last set of output.
Code: Select all
#include<cstdio>
#include<vector>
#include<iostream>
#include<algorithm>
#include<stack>
#include<map>
#include<string>
#include<cstring>
using namespace std;
int main() {
int c, i, f;
scanf("%d", &c);
for(i=0; i<c; i++) {
if(i) printf("\n");
vector<pair<long long, string> > v;
long long index;
char value[100000];
char w[1024];
while(scanf("%lld%[^0-9]", &index, w) > 0) {
v.push_back(make_pair(index, ""));
int len = strlen(w);
if(w[len-1] == '\n')
break;
}
int j;
for(j=0; j<v.size(); j++) {
scanf("%s", value, w);
string str(value);
v[j].second = str;
int len = strlen(w);
if(w[len-1] == '\n')
break;
}
sort(v.begin(), v.end());
vector<pair<long long, string> >::iterator k;
for(k = v.begin(); k != v.end(); k++) {
printf("%s\n", (k->second).c_str());
}
}
return 0;
}
Code: Select all
import java.io.*;
import java.util.*;
public class UVA482 {
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(bf.readLine());
for (int i = 0; i < N; i++){
bf.readLine();
String[] places = bf.readLine().trim().split(" ");
int[] place = new int[places.length];
for (int j = 0; j < places.length; j++){
place[j] = places[j].charAt(0)-'1';
}
String[] numbers = new String[places.length];
StringTokenizer st = new StringTokenizer(bf.readLine().trim());
for (int j = 0; j < places.length;j++){
numbers[j] = st.nextToken();
}
String [] newnum = new String[places.length];
for (int j = 0; j < places.length; j++){
newnum[place[j]] = numbers[j];
}
for (String f: newnum){
System.out.println(f);
}
if (i < N-1) System.out.println();
}
}
}
Code: Select all
import static java.lang.Integer.parseInt;
import static java.lang.System.exit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
class Main{
static void solve() throws IOException {
int nrTest = nextInt();
while(nrTest-- > 0){
in.readLine();
String [] index = in.readLine().split(" ");
String [] elements = in.readLine().split(" ");
String [] result = new String[elements.length];
for (int i = 0; i < result.length; i++) {
result[Integer.parseInt(index[i])-1] = elements[i];
}
for (int i = 0; i < result.length; i++) {
System.out.printf("%s\n",result[i]);
}
System.out.println();
}
}
static int nextInt() throws IOException {
return parseInt(next());
}
static String next() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public static void main(String[] args) {
try {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
solve();
in.close();
out.close();
} catch (IOException e){
e.printStackTrace();
exit(0);
}
}
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
}