写一个类,能接受int 型的变量,接收变量后能存储原变量(譬如12345)和其反向变量(54321),最多处理数量为10 个,当输入达到10 个或者输入变量为0 的时候停止。并且在类销毁前输出存储的所有变量。
写一个类,能接受int 型的变量,接收变量后能存储原变量(譬如12345)和其反向变量(54321),最多处理数量为10 个,当输入达到10 个或者输入变量为0 的时候停止。并且在类销毁前输出存储的所有变量。
输入若干个整数。
按类里存储的数个数m输出m行。每行两个数,表示原变量及其反向变量。
12 3442 0
12 21 3442 2443
注意反向后可能会有前导0
#include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> #include<math.h> #include<map> #include<queue> #include<iostream> #include<string> #include<limits.h> using namespace std; class Reverse{ public: int x; int y; Reverse(){} Reverse(int x){ this -> x = x; this -> y = getRev(); } private: int getRev(){ int t = x, r, q, tem = 0; while(t){ r = t % 10; q = t / 10; t = q; tem = (tem + r) * 10; } return tem / 10; } }; int main(){ int c = 0, m; while((cin >> m) && (m != 0) && (c != 10)){ c++; Reverse r(m); cout << r.x << " " << r.y << endl; } return 0; }
#include <iostream>
using namespace std;
class processInt{
public:
processInt(){
i = 0;
}
/*
~processInt(){
for(int j = 0;j<i;j++){
cout << origin[j] << " " << storage[j] << endl;
}
}
*/
void store(int v){
origin[i] = v;
storage[i] = negateInt(v);
i++;
}
void output(){
for(int j = 0;j<i;j++){
cout << origin[j] << " " << storage[j] << endl;
}
}
int i;
int storage[10];
int origin[10];
private:
int negateInt(int x){
int newV = 0;
while(x){
newV = newV * 10 + x%10;
x /= 10;
}
return newV;
}
};
int main(){
int x;
int count = 0;
processInt process;
while(cin >> x){
if(x==0){
process.output();
break;
}
process.store(x);
count ++;
if(count == 10){
process.output();
break;
}
}
return 0;
}
嘻嘻
#include<iostream> using namespace std; int main(){ int count=0; int n,a[10]; while(cin>>n){ if(count==10||n==0) break; a[count++]=n; } for(int i=0;i<count;i++){ cout<<a[i]<<" "; int temp=a[i],reverse=0; while(temp>0){ reverse=reverse*10+temp%10; temp/=10; } cout<<reverse<<endl; } }
#include<iostream> #include<stack> #include<vector> #include<cstring> #include<cmath> #include<algorithm> using namespace std; int main(){ string str; int count=10; while(cin>>str&&count!=0){ if(str=="0"){ break; } cout<<str<<" "; int len=str.size(); reverse(str.begin(),str.end()); while(str[0]=='0'){ str=str.substr(1); } cout<<str<<endl; count--; } }
#include<iostream> #include<algorithm> #include<string> #include<vector> using namespace std; typedef struct Num{ string num; string rnum; }Num; int main(){ string str; int count=0; while(cin>>str){ count++; if(count>10) break; if(str=="0"){ break; } cout<<str; for(int i=str.size()-1;i>=0;i--){ if(str[i]=='0') str.erase(i,1); } reverse(str.begin(),str.end()); cout<<" "<<str<<endl; //vec.push_back(n1); } }
import sys class Aim(object): def __init__(self) -> None: self.ll = [] def addNum(self, aa: int): self.ll.append(aa) def print(self): volume = min(10, len(self.ll)) for l in self.ll[: volume]: result = "" aa = str(l)[: :-1] pos = 0 for a in aa: if a != "0": break pos += 1 aa = aa[pos:] result = str(l) + " " + str(aa) print(result) aim = Aim() while True: try: a = list(map(int, input().split())) # print(a) for ss in a: if ss != 0:aim.addNum(ss) except Exception: aim.print() break
#include <iostream> #include <vector> using namespace std; class newInt{ public: newInt(){ this->len = 0; } void fun(){ int num; while (cin >> num) { this->len++; if(num == 0 || this->len > 10){ break; } this->my1.push_back(num); int reverse = 0,remain; while(num > 0){ remain = num % 10; reverse = reverse * 10 + remain; num /= 10; } this->my2.push_back(reverse); } } ~newInt(){ for(int i = 0;i < this->my1.size();++i){ cout << this->my1[i] << " " << this->my2[i] << endl; } } vector<int> my1; vector<int> my2; int len; }; int main() { newInt n; n.fun(); return 0; } // 64 位输出请用 printf("%lld")
#include <cstdio> int Reverse(int n){ int reverse = 0,remain; while(n != 0){ remain = n%10; n /= 10; reverse = reverse*10 + remain; } return reverse; } int main(){ int n, num = 0; while(scanf("%d",&n) != EOF){ num ++; if(n==0 || num>10) break; printf("%d %d\n",n,Reverse(n)); } return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; class rev{ public: int rongliang; string str[10]; rev(int x){ this->rongliang = x; } }; int main() { rev a(0); while(1){ if(a.rongliang == 10){ break; } cin >> a.str[a.rongliang]; if(a.str[a.rongliang] == "0"){ break; } cout << a.str[a.rongliang] << " "; reverse(a.str[a.rongliang].begin(),a.str[a.rongliang].end()); cout << a.str[a.rongliang] << endl; a.rongliang++; } }
#include <cstdio> #include <iostream> using namespace std; int reverse(int n){ int result=0; while(n!=0){ result*=10; result+=n%10; n/=10; } return result; } class obj{ private: int len; int origin[10]; int reorigin[10]; public: obj(){ int m=10; len=0; for(int i=0,temp;i<m;i++){ scanf("%d",&temp); if(temp==0){ break; } origin[i]=temp; reorigin[i]=reverse(temp); ++len; } } ~obj(){ for(int i=0;i<len;i++){ cout<<origin[i]<<" "<<reorigin[i]<<endl; } } }; int main() { obj o1; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { int c=0; string s; while(cin>>s && s!="0") { string s1; c++; cout << s << " "; for(int i=s.size()-1;i>0;i--) { if(s[i]=='0') continue; else s1+=s[i]; } s1+=s[0]; cout << s1 << endl; if(c==10) break; } return 0; }
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); for (int i = 0; i < 10; i++){ int num = sc.nextInt(); if (num == 0){ break; } else { System.out.println(num + " " + rev(num)); } } sc.close(); } static String rev(int num){ String str = ""; String s1 = String.valueOf(num); int len = s1.length(); int i; for (i = len-1; i >=0; i--){ if (s1.charAt(i) != '0'){ break; } } for (int j = i; j >= 0; j--){ str += s1.charAt(j); } return str; } }
#include<iostream> using namespace std; class Cls{ private: int a[10]; int index=0; public: bool place(int x){ if(index==10 || x==0) return false; a[index++]=x; return true; } int len(){ return index; } int get_i(int i){ return a[i]; } }; int main(){ Cls cls; int x; while(scanf("%d",&x)!=EOF){ if(!cls.place(x)) break; } for(int i=0;i<cls.len();i++){ int t=cls.get_i(i); cout<<t<<" "; int k=0; while(t!=0){ k=10*k+t%10; t=t/10; } cout<<k<<endl; } return 0; }
#include<iostream> (720)#include<string> using namespace std; class IntDispose{ private: int ori[10] = {0}; int rev[10] = {0}; int process(int a){ int b=0; int quotient,remainder; while(a!=0){ b *= 10; quotient = a/10; remainder = a%10; b += remainder; a = quotient; } return b; } public: IntDispose(int a[]){ for (int i=0;a[i]!=0&&i<10;i++){ ori[i] = a[i]; rev[i] = process(ori[i]); } } ~IntDispose(){ for(int i=0;ori[i]!=0&&i<10;i++){ cout<<ori[i]<<" "<<rev[i]<<endl; } } }; int main(){ int x,i=0; int a[10]={0}; while(cin>>x){ if(x==0)break; a[i] = x; if(i>9)break; char c = getchar(); i++; } IntDispose In = IntDispose(a); return 0; }