Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void main ()
- {
- const int LENGTH = 5;
- int num[LENGTH] = {1000,100,300,200,600};
- int temp;
- std::string str{LENGTH} = {"国語","英語","現社","おばお","あほ"}
- std::string stTemp;
- std::cout << "ソート前 - > ";
- for(int i = 0; i < LENGTH;i++)
- {
- std::cout<< num[i];
- if(i < LENGTH - 1) std::cout <<":";
- }
- std::cout << std::endl;
- //ソート
- for(int i = 0; i < LENGTH;i++)
- {
- for(int j = LENGTH - 1; j >= i; j--)
- {
- if(num[j - 1] > num[j])
- {
- //数字のソート
- temp = num[j - 1];
- num[j - 1] = num[j];
- num[j] = temp;
- //文字のソート
- stTemp = str[j - 1];
- str[j-1] = str[j];
- str[j] = stTemp;
- }
- }
- }
- std::cout << "ソート後 - > ";
- for(int i = 0; i < LENGTH;i++)
- {
- std::cout<< num[i];
- if(i < LENGTH - 1) std::cout <<":";
- }
- std::cout << std::endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement