不用字符串方法,wa了#2#3#4#19,求调
查看原帖
不用字符串方法,wa了#2#3#4#19,求调
1087173
guer_loser_lcz楼主2023/11/18 10:40
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
char s[30];
unsigned long long a,b,p,k;
unsigned long long fz(unsigned long long x){
	unsigned long long y=0;
	while(x){
		y*=10;
		y+=(x%10);
		x/=10;
	}
	return y;
}
int main(){
	while(cin>>s[k])k++;
	for(int i=0;i<k;i++){
		if(s[i]=='/'){
			p=1;
			break;
		}
		if(s[i]=='%'){
			p=2;
			break;
		}
		if(s[i]=='.'){
			p=3;
			break;
		}
	}
	if(p==0){
		for(int i=k-1;i>=0;i--){
			cout<<s[i];
		}
	}
	if(p==2){
		sscanf(s,"%d%",&a);
		cout<<fz(a)<<"%";
	}
	if(p==3){
		sscanf(s,"%lld.%lld",&a,&b);
		cout<<fz(a)<<"."<<fz(b);
	}
	if(p==1){
		sscanf(s,"%lld/%lld",&a,&b);
		cout<<fz(a)<<"/"<<fz(b);
	}
	return 0;
}
2023/11/18 10:40
加载中...