hdu1062 text reverse题目的分析
时间: 2024-05-22 07:14:26 浏览: 11
题目描述:
给定一个字符串,将其中的单词顺序翻转过来。
输入格式:
共一行,为一个字符串。字符串长度不超过1000,其中单词用空格隔开,每个单词长度不超过100。
输出格式:
共一行,为翻转后的字符串。
思路分析:
这道题思路很简单,就是把每个单词分离出来,然后按照相反的顺序输出即可。
代码实现:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string s;
getline(cin,s); //读入一个有空格的字符串
stringstream ss(s); //将字符串转为流
string temp; //存储单词
vector<string> v; //存储单词的容器
while(ss>>temp) //从流中读入单词,存储到容器中
v.push_back(temp);
for(int i=v.size()-1;i>=0;i--) //倒序输出单词
{
cout<<v[i];
if(i!=0) cout<<" "; //注意单词之间的空格
}
return 0;
}
笑话:
为什么程序员总是喜欢用黑色背景?因为他们喜欢黑客。
相关问题
hdu1969 java
好的,我明白了。针对你的问题,我猜测你是在问如何使用Java解决hdu1969这道题目。如果我的猜测正确,那么我可以给你一些思路和代码实现。
首先,我们需要明确题目的意思。题目要求我们求出一个多边形的面积,这个多边形由若干个点组成。我们可以使用海龙公式来计算多边形的面积,具体实现如下:
```java
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
while (n-- > 0) {
int m = scanner.nextInt();
double x1 = scanner.nextDouble();
double y1 = scanner.nextDouble();
double x2 = scanner.nextDouble();
double y2 = scanner.nextDouble();
double x3 = scanner.nextDouble();
double y3 = scanner.nextDouble();
double a = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
double b = Math.sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
double c = Math.sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
double p = (a + b + c) / 2;
double s = Math.sqrt(p * (p - a) * (p - b) * (p - c));
System.out.printf("%.2f\n", s);
}
}
}
```
以上代码实现了对hdu1969题目的求解,你可以将其复制到你的Java IDE中进行编译和运行。
java HDU2020
题目描述:输入n(n<=100)个整数,按照绝对值从大到小排序后输出。题目保证对于每一个测试实例,所有的数的绝对值都不相等。
以下是Java HDU2020的代码实现:
```java
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int n = sc.nextInt();
Integer[] a = new Integer[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return Math.abs(o2) - Math.abs(o1);
}
});
for (int i = 0; i < n - 1; i++) {
System.out.print(a[i] + " ");
}
System.out.println(a[n - 1]);
}
sc.close();
}
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)