1

I use strings to present information and it's a hex string. And the shape of these string sequences is a rectangle. However, I want to change the shape to a circle by deleting the useless hex number and replacing by "0"

for example: the hex string is

"f1ffffffff"
"ff2fffffff"
"fff3ffffff"
"ffff4fffff"
"fffff5ffff"
"ffffff6fff"
"fffffff7ff"
"ffffffff8f"
"fffffffff9"
"ffffffffff"

the output hex string in a shape of circle is

"000ffff000"
"002fffff00"
"0ff3fffff0"
"0fff4ffff0"
"fffff5ffff"
"ffffff6fff"
"0ffffff7f0"
"0fffffff80"
"00ffffff00"
"000ffff000"

I've tried to use a programme of generating circle as follows:

void main() 
{
    int radius;
    cout << "Input circle's radius: ";
    cin >> radius;
    for (int i = 1; i <= radius*2; i++) 
    cout << "=";
    cout << endl;
    for (int x = 1; x < radius*2; x++) 
    {
        for (int y = 1; y < radius*2; y++)
        {
            if (abs(y - radius) * abs(y - radius) + abs(x - radius) * abs(x - radius) <= radius * radius) 
            cout << "ff11";
            else cout << " ";
        }
        cout << endl;
    }
}

The problem I meet is the programme changes the position of hex string but not delete the useless hex. Could someone help me with my code?

EDIT:

The example above is a ten-string-sequence with ten hex numbers per string, which were generated by me. I want to re-shape the seq 1 makes it look like a circle(seq 2 "0" represents "there's no word"). So for the first line I remove the first three hex numbers and last three hex numbers and replaced by "0", these six numbers are so called "useless hex", and so on.

The code i use can print a circle, but it's not exactly what i want. I have problem to realize the function. If someone help me changing some code or changing totally I would be very thankful.

Qingyao Li
  • 173
  • 2
  • 11
  • Use of `cout << ...` clearly indicates that you're using C++ rather than C, so I've changed the tag accordingly. – Caleb Jul 17 '13 at 13:40
  • 2
    What output do you get? What does "delete the useless hex" mean? – interjay Jul 17 '13 at 13:41
  • Use of void main() also indicates that it is not c++ :) – mars Jul 17 '13 at 13:52
  • @mars, you mean *is* C++, *not* C, right? :) – pattivacek Jul 17 '13 at 13:59
  • what do you mean by 'useless hex'? And I didn't see any character except for `f` in your code. where is `1`...`9`? – Annie Kim Jul 17 '13 at 14:38
  • @patrickvacek I think `void main()` is neither `C++` nor `C`... Despite the fact that it seems so mind-bogglingly popular/prevalent/common/whatever... – twalberg Jul 17 '13 at 14:40
  • @patrickvacek As twalberg says, the return type `void` is not standard conforming c++. I don't know if the compiler must check for it of if you just get undefined behaviour. – mars Jul 17 '13 at 14:58
  • @twalberg and @mars, thank you, I stand corrected! According to http://stackoverflow.com/a/5296593/289099 `void main...` is not valid for C nor C++ in normal hosted environments. Of course, this only further complicates our attempts to understand the OP's situation. – pattivacek Jul 17 '13 at 15:12
  • @interjay does my edit answer your question? – Qingyao Li Jul 17 '13 at 15:30
  • @AnnieKim i have improved my question. there is 1 or 2....or 9 in seq 1. – Qingyao Li Jul 17 '13 at 15:35
  • 1
    So you want to take the first hex string as input and produce the second hex string as output? Your code does not take any input except for the radius. – interjay Jul 17 '13 at 15:55
  • @interjay Yes. At first I want to realize that function by modifying the code. But it seems quite hard. Input can be any hex string like seq 1 and the output format is like seq 2. – Qingyao Li Jul 18 '13 at 04:42

1 Answers1

0

Replace

cout << "ff11";

with one character instead of four, for example

cout << "f";

Then you will get what you want.

Yu Hao
  • 119,891
  • 44
  • 235
  • 294
Valner
  • 36
  • 2