解题思路:
给朋友写的,写的时候看错了题··代码结构不大好,但是思路的提交是正确的。
注意事项:
参考代码:
#include<iostream> using namespace std; int n; int *sz; bool Judge() { int i,count1=0; for(i=0;i<n;i++) if(sz[i]!=0)count1++; if(count1==2)return false; else return true; } void Found() { int i=0,j=0; for(;i<n;i++) { if(sz[i]!=0) cout<<sz[i]<<" "; } } void Count() { int count1=0,i=0; int t=0; while(t<n-2) { if(i==n){i = 0;count1=0;}; if(sz[i]!=0)count1++; if(count1 ==2) { cout<<sz[i]<<" "; sz[i] = 0; count1 = 0; t++; } i++; } } int main() { while(cin>>n){ sz = new(int [n]); for(int i=0;i<n;i++) { sz[i] = i+1; } Count(); cout<<endl; Found(); delete(sz); } cout<<endl; return 0; }
0.0分
0 人评分
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:859 |
A+B for Input-Output Practice (III) (C语言代码)浏览:569 |
【偶数求和】 (C语言代码)浏览:639 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:619 |
IP判断 (C语言描述,蓝桥杯)浏览:1094 |
蚂蚁感冒 (C语言代码)浏览:1319 |
1014题解浏览:484 |
C语言程序设计教程(第三版)课后习题9.4 (C语言代码)浏览:629 |
GC的苦恼 (C语言代码)浏览:618 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:946 |