首页
DreamJudge
院校信息
专业题库
模拟考试
机试真题
上岸课程
兑换中心
登录
注册
上岸
以下题解仅供学习参考使用。
抄袭、复制题解,以达到刷AC率/AC数量或其他目的的行为,在N诺是严格禁止的。
N诺非常重视学术诚信。此类行为将会导致您成为作弊者。具体细则请查看N诺社区规则。
Candour
2024年5月29日 19:51
字符串排序3(C++) 题解:
P1261
回复 1
|
赞 8
|
浏览 957
#include<bits/stdc++.h> using namespace std; int n; bool cmp(string a, string b) { return a.size() < b.size(); } int main() { while(cin >> n) { vector<string> res; for(int i = 0; i <= n; i ++) { string s...
遨游
2024年3月18日 16:25
字符串排序3 题解 使用getline前需要用getchar()吸收换
P1261
回复 0
|
赞 7
|
浏览 1.0k
#include <iostream> #include <string> #include <algorithm> using namespace std; int compare(string a,string b){ return a.length()<b.length(); } int main(){ int n; while(cin>>n){ ...
huanghu
2024年3月16日 18:13
字符串排序3 题解:
P1261
回复 0
|
赞 1
|
浏览 762
#include<stdio.h> #include<iostream> #include<string> #include<algorithm> using namespace std; bool cmp(string s1,string s2){ return s1.length() < s2.length(); } int main(){ int n; while(cin>>n){ string arr[100]; int cnt=0; cin.ignore()...
promising
2024年3月8日 17:02
字符串排序3 题解:
P1261
回复 3
|
赞 4
|
浏览 1.2k
感觉没有写错啊,但是没有输出,有没有佬帮忙看看哪里有问题,跪谢 #include<stdio.h> #include<string.h> int main() { int n; int i,j; char a[100][100]; char t[100]; while((scanf("%d",&n))!=EOF) ...
Yw1111111
2024年3月8日 15:21
字符串排序3 题解:Python
P1261
回复 0
|
赞 0
|
浏览 640
1261 AC while True: try: string = [] n = int(input()) for i in range(n): sentence = input() if sentence == &...
小王桐学
2024年2月22日 23:12
字符串排序3 题解:C题解
P1261
回复 0
|
赞 3
|
浏览 1.0k
无语!!!! #include <stdio.h> #include <string.h> void Sort(char s[][100],int n) { int i,j; char t[100]; for(i = 0; i < n-1; i++) for(j = 1; j < n-i; j++) if(strlen(s[j]) < strlen(s[j-1])) { strcpy(t,s[j]); strcpy(s[j],s[j-1]); strcpy(s[j...
Hegel
2023年3月28日 17:11
使用cin后立即使用getline会造成的问题
P1261
回复 0
|
赞 1
|
浏览 2.6k
#include <iostream> #include <string> using namespace std; void BubbleSort(string* a, int n) { for (int i = 0, flag = 0; i < n; i++) { for (int j = 1; j < n - i; j++) if (a[j].size() < a[j - 1].size()) { swap(a[j], a[j - 1]); flag = 1; } if (f...
wenjuice
2022年3月7日 16:59
getline与cin一起使用的问题
P1261
回复 1
|
赞 6
|
浏览 6.6k
cin换行后会在缓冲区剩余 '\n',如果紧接着使用getline(),会直接读取为空字符串,导致输入有问题 解决:在cin之后getline之前,使用cin.ignore(); 这坑害我调试了好久! #include<iostream> #include<string> #include<algorithm> using namespace std; typedef struct { string str; int len; } Str; bool cmp(Str a, Str b) ...
Dear_Mr_He
2021年12月7日 15:13
提问
P1261
回复 0
|
赞 1
|
浏览 6.1k
一开始的写的一份代码,没用getchar()把缓存里的回车干掉,并且是通过scanf("%d\n", &n)来获取字符串个数的输入,但是Output Limit Exceeded,就是下面会多出很多换行,不过我在本地上是正常的,代码如下。 #include<bits/stdc++.h> using namespace std; bool cmp(string s1, string s2) { return s1.length() < s2.length(); } int main() { int n; w...
N诺子言
2021年3月10日 16:37
getline前回车
P1261
回复 0
|
赞 0
|
浏览 8.4k
#include<bits/stdc++.h> #define MAXINT 32767 using namespace std; typedef long long ll; bool cmp(string a,string b) { return a.size()<b.size(); } int main() { int n; while(cin>>n) { string a[n]; for(int i=0;i<n;i++) { string s;...
1
2
3
题目
字符串排序3
题解数量
23
发布题解
在线答疑
热门题解
1
注意使用getchar写cmp函数 size() 比较大小就可以了
2
字符串排序3 题解:使用vector +sort(),此方法适用于多种场景
3
字符串排序3 题解:getchar compare自定义
4
字符串排序3(C++) 题解:
5
字符串排序3 题解 使用getline前需要用getchar()吸收换行符
6
字符串排序3 题解:
7
getline与cin一起使用的问题
8
字符串排序3 题解:
9
字符串排序3 题解:
10
字符串排序3 题解: