我需要帮助编写程序来打印所有点的最大X值 [英] I need help in writing program to print the maximum X value of all points

查看:64
本文介绍了我需要帮助编写程序来打印所有点的最大X值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要帮助编写这个程序..需要打印所有点的最大X值。
此字符串中的
多边形= [(1,1) ,(4,1),(4,5),(1,5);(3,4),(6,4),(6,12),(3,12)]



我尝试了什么:



i need help in writing this program..it's required to Print the maximum X value of all points.
in this string: Polygons=[(1,1),(4,1),(4,5),(1,5);(3,4),(6,4),(6,12),(3,12)] .

What I have tried:

#include <iostream>
#include <string>
using namespace std ;
int main (){
  int maximum=0 ;string s=("[(1,1),(4,1),(4,5),(1,5);(3,4),(6,4),(6,12),(3,12)]");int x=0;
int n= s.length() ;
int d;
for (d=0;d<100;d++)
 cin>> s[d];
  maximum =  s[0];
for (d=0;d<100;d++)

{ 
	if (x==1){
		maximum=x;
if (s[d]>maximum){
maximum=s[d];
 x=s.find(maximum,x+1);

}
}

}
cout<<"the maximum:"<<endl ;
}
 int maximum=0 ;string s=("[(1,1),(4,1),(4,5),(1,5);(3,4),(6,4),(6,12),(3,12)]");int x=0;
int n= s.length() ;
int d;
for (d=0;d<100;d++)
 cin>> s[d];
  minimum=  s[0];
for (d=0;d<100;d++)

{ 
	if (x==1){
		maximum=x;
if (s[d]>maximum){
maximum=s[d]; x=s.find(maximum,x+1);
}
}

}
cout<<"the maximum:"<<endl ;
}

推荐答案

目前尚不清楚 WHAT 你的问题,但我有一些提示。



当你为输入使用点结构时会变得更容易,所以输入是一个点数组。并为调试做一些输出。



It is not clear WHAT your problem is, but I have some tips.

It is getting easier when you use a point structure for the input, so your input is a point array. And make some output for debugging.

typedef struct {
 int x;
 int y;
} POINT;
POINT point[] = { {0,1}, {1,2} };
//access struct
if( point[1].x > point[0].x ) {
 max = point[1].x;
cout << "New max " << max;
}



如果你真的想要努力并使用字符串输入,你需要 atoi 转换为数字并 strtok


如前所述,如果你能接受一系列结构的输入,那么你的生活会更容易。另一方面,如果输入字符串是要求,那么你必须解析它,以获得点数组,然后计算结果。

幸运地解析这样一个常规字符串应该很容易,你可以搜索数字分隔符,即'('', '')'字符。

查看 string :: find [ ^ ]方法。
As already suggested, if you can accept inputs from an array of structs then your life would be easier. On the other hand, if an input string is the requirement then you have to parse it, in order to get the array of points and then compute the result.
Luckily parsing such a regular string should be easy, you may search for the number separators, namely the '(', ',',')' characters.
Check out the string::find[^] method.


这篇关于我需要帮助编写程序来打印所有点的最大X值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆